Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.bitstep.BitStep;
- import com.bitstep.database.classes.dbShop;
- import com.bitstep.database.classes.dbUser;
- import com.bitstep.utils.EmailFactory;
- import com.liqpay.LiqPay;
- import org.apache.log4j.Logger;
- import org.json.simple.JSONArray;
- import org.json.simple.JSONObject;
- import ru.tsyklop.web.WebCookies;
- import ru.tsyklop.web.WebHashes;
- import ru.tsyklop.web.WebRequest;
- import ru.tsyklop.web.WebSession;
- import java.io.File;
- import java.sql.SQLException;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.HashMap;
- import static com.bitstep.BitStep.*;
- /**
- * Created by sloyev_php on 23.05.2017.
- */
- public class UserModel implements Model {
- private int ID;
- private String HASH;
- private String MESSAGE;
- private boolean AUTH;
- private boolean ADMIN;
- private boolean ERROR = false;
- private boolean SUCCESS = false;
- private boolean MOBILE = false;
- private boolean PARAMETERS = false;
- private boolean VERIFICATION = false;
- private boolean AUTHENTICATION = false;
- private dbUser dbUser;
- private dbShop dbShop;
- private WebRequest UTILS;
- private WebSession SESSION;
- private WebCookies COOKIES;
- private WebHashes HASHES;
- private EmailFactory EMAIL;
- private JSONObject result = new JSONObject();
- public static final int USER_ACTION_CONNECT = 0;
- public static final int USER_ACTION_LOGIN = 1;
- public static final int USER_ACTION_REGISTER = 2;
- public static final int USER_ACTION_FACEBOOK = 3;
- public static final int USER_ACTION_LOGOUT = 4;
- public static final int USER_ACTION_FORGOT = 5;
- public static final int USER_ACTION_GET_INFO = 6;
- public static final int USER_ACTION_GET_DATE = 7;
- public static final int USER_ACTION_GET_DAY = 8;
- public static final int USER_ACTION_GET_WEEK = 9;
- public static final int USER_ACTION_GET_MONTH = 10;
- public static final int USER_ACTION_UPDATE_INFO = 11;
- public static final int USER_ACTION_UPDATE_PASSWORD = 12;
- public static final int USER_ACTION_ADD_STEPS = 13;
- public static final int USER_ACTION_UPDATE_STEPS = 14;
- public static final int USER_ACTION_GET_PARTNERS = 15;
- public static final int USER_ACTION_GET_WEB = 16;
- public static final int USER_ACTION_GET_RESULTS = 17;
- public static final int USER_ACTION_SHOP_BUY = 50;
- public static final int USER_ACTION_SHOP_GET_ALL_LIST = 51;
- public static final int USER_ACTION_SHOP_GET_USER_LIST = 52;
- public static final int USER_ACTION_SHOP_GET_CLOTH_LIST = 53;
- public static final int USER_ACTION_SHOP_GET_PERSON_LIST = 54;
- public static final int USER_ACTION_SHOP_GET_WEEKENDS_PRODUCTS = 55;
- public static final int USER_ACTION_SHOP_GET_COINS_PRODUCTS = 56;
- public static final int USER_ACTION_SHOP_GET_VIP_PRODUCT = 57;
- public static final int USER_ACTION_SHOP_BUY_CLOTH= 58;
- public static final int USER_ACTION_SHOP_BUY_PERSON= 59;
- public static final int USER_ACTION_ERROR = -1;
- public static final int USER_ACTION_PARAMETERS = -2;
- public static final int USER_ACTION_VERIFICATION = -3;
- private static final Logger LOGGER = Logger.getLogger(UserModel.class);
- public UserModel(WebRequest UTILS) {
- if (UTILS != null) {
- this.UTILS = UTILS;
- SESSION = UTILS.getSession();
- COOKIES = UTILS.getCookies();
- HASHES = UTILS.getHashes();
- this.AUTH = SESSION.getBoolean("AUTH");
- this.ADMIN = SESSION.getBoolean("ADMIN");
- MOBILE = UTILS.containsHeader("mobile");
- if (!this.MOBILE) {
- this.ID = SESSION.getInt(BitStep.SESSION_USER_ID);
- this.HASH = SESSION.getString(BitStep.SESSION_USER_HASH);
- } else if(UTILS.containsHeader("key")) {
- String [] sKey = UTILS.getHeaderString("key").split(BitStep.USER_HASH_SPLITTER);
- if(sKey.length > 0) {
- if(sKey[0]!=null&&sKey[1]!=null) {
- this.ID = Integer.parseInt(sKey[0]);
- this.HASH = sKey[1];
- }
- }
- } else {
- this.ID = 0;
- this.HASH = "";
- }
- this.EMAIL = new EmailFactory(UTILS.getRoot());
- dbUser = new dbUser();
- dbShop = new dbShop();
- }
- }
- public int getID() {
- return this.ID;
- }
- public String getHASH() {
- return this.HASH;
- }
- public boolean isAuth() {
- return this.AUTH;
- }
- public boolean isAdmin() {
- return this.ADMIN;
- }
- public EmailFactory getEMAIL() {
- return EMAIL;
- }
- public void Error() {
- ERROR = true;
- MESSAGE = "Error! Please try again";
- }
- public void Error(String mgs) {
- ERROR = true;
- MESSAGE = mgs;
- }
- public void Success() {
- SUCCESS = true;
- MESSAGE = "Успех.";
- }
- public void Success(String mgs) {
- SUCCESS = true;
- MESSAGE = mgs;
- }
- public void Parameters() {
- PARAMETERS = true;
- }
- public void Verification() {
- VERIFICATION = true;
- }
- public void Authentication() {
- AUTHENTICATION = true;
- }
- public JSONObject Execute(int type) throws Exception {
- if(type >= 0) {
- result.clear();
- //System.out.println(UTILS.getParams().toJSONString());
- switch (type) {
- case USER_ACTION_ERROR:
- Error();
- break;
- case USER_ACTION_PARAMETERS:
- Parameters();
- break;
- case USER_ACTION_VERIFICATION:
- Verification();
- break;
- case USER_ACTION_CONNECT:
- Connect();
- break;
- case USER_ACTION_LOGIN:
- Login(UTILS.getParams(), false);
- break;
- case USER_ACTION_REGISTER:
- Register(false);
- break;
- case USER_ACTION_FACEBOOK:
- Facebook();
- break;
- case USER_ACTION_LOGOUT:
- Logout();
- break;
- case USER_ACTION_FORGOT:
- Forgot();
- break;
- case USER_ACTION_GET_INFO:
- GetInfo();
- break;
- case USER_ACTION_GET_DATE:
- GetDate();
- break;
- case USER_ACTION_GET_WEEK:
- GetWeek(UTILS.getParamString("date"));
- break;
- case USER_ACTION_GET_DAY:
- GetDay(UTILS.getParamString("date"));
- break;
- case USER_ACTION_GET_MONTH:
- GetMonth(UTILS.getParamString("date"));
- break;
- case USER_ACTION_UPDATE_INFO:
- UpdateInfo();
- break;
- case USER_ACTION_UPDATE_PASSWORD:
- UpdatePassword();
- break;
- case USER_ACTION_ADD_STEPS:
- AddSteps();
- break;
- case USER_ACTION_UPDATE_STEPS:
- UpdateSteps();
- break;
- case USER_ACTION_SHOP_BUY:
- ShopBuy();
- break;
- case USER_ACTION_SHOP_GET_ALL_LIST:
- //ShopGetAllProducts();
- break;
- case USER_ACTION_SHOP_GET_USER_LIST:
- ShopGetUserProducts();
- break;
- case USER_ACTION_SHOP_GET_CLOTH_LIST:
- ShopGetClothProducts();
- break;
- case USER_ACTION_SHOP_GET_PERSON_LIST:
- ShopGetPersonProducts();
- break;
- case USER_ACTION_SHOP_GET_WEEKENDS_PRODUCTS:
- ShopGetWeekendsProducts();
- break;
- case USER_ACTION_SHOP_GET_COINS_PRODUCTS:
- ShopGetCoinsProducts();
- break;
- case USER_ACTION_SHOP_GET_VIP_PRODUCT:
- ShopGetVipProduct();
- break;
- case USER_ACTION_SHOP_BUY_CLOTH:
- ShopBuyCloth();
- break;
- case USER_ACTION_SHOP_BUY_PERSON:
- ShopBuyPerson();
- break;
- case USER_ACTION_GET_PARTNERS:
- GetPartners();
- break;
- case USER_ACTION_GET_WEB:
- GetWeb();
- break;
- case USER_ACTION_GET_RESULTS:
- GetResults();
- break;
- default:
- break;
- }
- } else {
- Error();
- }
- if (SUCCESS) {
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_SUCCESS);
- result.put(BitStep.TYPE_MESSAGE, MESSAGE);
- }
- if (ERROR) {
- result.clear();
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_ERROR);
- result.put(BitStep.TYPE_MESSAGE, MESSAGE);
- }
- if(PARAMETERS) {
- result.clear();
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_ERROR);
- result.put(BitStep.TYPE_MESSAGE, "Input data not received");
- }
- if(AUTHENTICATION) {
- result.clear();
- result.put(BitStep.TYPE_AUTHENTICATION, BitStep.TYPE_ERROR);
- result.put(BitStep.TYPE_MESSAGE, "Server authentication error");
- }
- dbUser.close();
- dbShop.close();
- return result;
- }
- /* METHODS */
- private void Connect() {
- boolean user = false;
- try {
- String hKey = UTILS.getHeaderString("key");
- if (hKey != null && !hKey.isEmpty()) {
- String[] res = hKey.split(BitStep.USER_HASH_SPLITTER);
- if (res.length > 0 && res[0]!=null&&res[1]!=null) {
- int id = Integer.parseInt(res[0]);
- String hash = res[1];
- if (id > 0 && !hash.isEmpty()) {
- if (dbUser.CheckAuthUser(id, hash)) {
- String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
- dbUser.SetVisited(id, date);
- user = true;
- GetInfo();
- UserUpdateDeviceAndPush(id);
- result.put("coin", dbUser.GetUserCoinOnDate(id, date));
- }
- }
- }
- }
- if (user) {
- result.put("user", true);
- } else {
- result.put("user", false);
- }
- } catch (Exception e) {
- e.printStackTrace();
- result.put("user", false);
- }
- //result.put(BitStep.TYPE_STATUS, BitStep.TYPE_SUCCESS);
- Success();
- }
- private JSONObject Login(JSONObject data, boolean fb) throws Exception {
- if(!isAuth()) {
- if ((!fb&&data.containsKey("email")&&data.containsKey("password"))||(fb&&data.containsKey("email"))) {
- data = CheckAuthData(data, fb);
- if (!data.containsKey(BitStep.TYPE_TEXT_ERROR)) {
- if(!fb) {
- data.replace("password", HASHES.hashPassword(data.getString("email"), data.getString("password")));
- System.out.println(data.getString("password"));
- data.put("hash", HASHES.generate((data.getString("email")+data.getString("password")+HASHES.generate(10)), 64));
- }
- data = dbUser.Login(data, fb);
- if (data.getString(BitStep.TYPE_STATUS).equals(BitStep.TYPE_TEXT_SUCCESS)) {
- AUTH = true;
- dbUser.SetVisited(data.getInt("id"), new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
- if(data.containsKey("mail")) {
- EMAIL.Send(data.getString("email"), 5, UTILS.BuildUrl(UTILS.getHeaderString("host"), "confirm", HASHES.generateToken(UTILS.getRequest())));
- }
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_SUCCESS);
- result.put(BitStep.TYPE_MESSAGE, "Вы успешно авторизовались");
- if(MOBILE) {
- ID = data.getInt("id");
- UserUpdateDeviceAndPush(ID);
- result.put("id", data.getInt("id"));
- result.put("key", data.getInt("id")+BitStep.USER_HASH_SPLITTER +data.getString("hash"));
- GetInfo();
- GetMonth(new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()));
- } else {
- result.put("url", "/account");
- result.put("id", data.getInt("id"));
- result.put("hash", data.getString("hash"));
- SESSION.set("AUTH", true);
- SESSION.set(BitStep.SESSION_USER_ID, data.getInt("id"));
- SESSION.set(BitStep.SESSION_USER_HASH, data.getString("hash"));
- JSONObject u = new JSONObject();
- u.put("id", data.getInt("id"));
- u.put("hash", data.getString("hash"));
- u.put("remember", true);
- COOKIES.create("/", "user", u, BitStep.COOKIES_AGE);
- }
- } else {
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_ERROR);
- if (data.getString(BitStep.TYPE_STATUS).equals(BitStep.TYPE_EMPTY)) {
- result.put(BitStep.TYPE_MESSAGE, "E-Mail или пароль неверны");
- } else if (data.getString(BitStep.TYPE_STATUS).equals(BitStep.TYPE_ALREADY)) {
- result.put(BitStep.TYPE_MESSAGE, "Вы уже авторизованы");
- } else if(data.getString(BitStep.TYPE_STATUS).equals(BitStep.TYPE_CONFIRM)) {
- result.put(BitStep.TYPE_MESSAGE, "E-Mail не подтвержден");
- } else {
- Error();
- }
- }
- } else {
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_ERROR);
- JSONObject error = (JSONObject) data.get(BitStep.TYPE_TEXT_ERROR);
- if (error.containsKey("email")) {
- result.put("email", error.getString("email"));
- }
- if (error.containsKey("password")) {
- result.put("password", error.getString("password"));
- }
- if (error.containsKey("error")) {
- result.put(BitStep.TYPE_MESSAGE, error.getString("error"));
- }
- }
- } else {
- Error();
- }
- } else {
- Error();
- }
- return result;
- }
- private JSONObject Register(boolean fb) throws Exception {
- if(!AUTH) {
- JSONObject data = UTILS.getParamJSONObject("data");
- if (!data.isEmpty()) {
- data = CheckRegisterData(data, fb);
- if (!data.containsKey(BitStep.TYPE_TEXT_ERROR)) {
- if (!fb) {
- data.put("confirm", 0);
- data.replace("p1", HASHES.hashPassword(data.getString("email"), data.getString("p1")));
- } else {
- data.put("confirm", 1);
- data.put("np", HASHES.generate(10));
- data.put("p1", HASHES.hashPassword(data.getString("email"), data.getString("np")));
- }
- data = dbUser.Register(data);
- if (!data.containsKey(BitStep.TYPE_TEXT_ERROR)) {
- result.put("id", data.getInt("id"));
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_SUCCESS);
- result.put(BitStep.TYPE_MESSAGE, "Вы успешно зарегистрировались");
- String token = HASHES.generateToken(UTILS.getRequest());
- if (!fb && dbUser.AddConfirmRegister(data.getString("email"), token)) {
- EMAIL.Send(data.getString("email"), 1, UTILS.BuildUrl(UTILS.getHeaderString("host"), "confirm", token));
- }
- if (fb) {
- result.put("data", data);
- EMAIL.Send(data.getString("email"), 4, data.getString("np"));
- }
- JSONObject adt = new JSONObject();
- if (data.containsKey("additions")) {
- adt = CheckAddition(((JSONObject) data.get("additions")), (data.getString("gender").equals("male")?1:2));
- } else {
- adt = GetEmptyAdditions((data.getString("gender").equals("male")?1:2));
- }
- dbUser.AddAdditions(data.getInt("id"), adt);
- if (!MOBILE) {
- result.put("url", "/");
- }
- } else {
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_ERROR);
- JSONObject error = (JSONObject) data.get(BitStep.TYPE_TEXT_ERROR);
- String status = error.getString(BitStep.TYPE_STATUS);
- if (status.equals(BitStep.TYPE_EXIST)) {
- result.put(BitStep.TYPE_MESSAGE, "Этот E-Mail адресс уже существует");
- } else {
- Error();
- }
- }
- } else {
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_ERROR);
- JSONObject error = (JSONObject) data.get("error");
- if (error.containsKey("firstname")) {
- result.put("firstname", error.get("firstname"));
- }
- if (error.containsKey("lastname")) {
- result.put("lastname", error.get("lastname"));
- }
- if (error.containsKey("email")) {
- result.put("email", error.get("email"));
- }
- if (error.containsKey("p1")) {
- result.put("p1", error.get("p1"));
- }
- if (error.containsKey("p2")) {
- result.put("p2", error.get("p2"));
- }
- if (error.containsKey("gender")) {
- result.put("gender", error.get("gender"));
- }
- }
- } else {
- Parameters();
- }
- } else {
- Error();
- }
- return result;
- }
- private void Logout() throws Exception {
- if(AUTH) {
- if(ID > 0) {
- if(dbUser.Logout(ID)) {
- if (!MOBILE) {
- SESSION.remove("ID");
- SESSION.remove("HASH");
- COOKIES.remove("user");
- }
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_SUCCESS);
- result.put(BitStep.TYPE_MESSAGE, "Вы успешно вышли");
- }
- } else {
- Parameters();
- }
- } else {
- Authentication();
- }
- }
- private void Forgot() throws Exception {
- if(!AUTH) {
- if(UTILS.containsParam("email")) {
- String email = UTILS.getParamString("email");
- if(!email.isEmpty()) {
- if(email.matches(BitStep.EMAIL_REGEXP)) {
- int id = dbUser.CheckUserByEmail(email);
- if(id > 0) {
- String token = HASHES.generateToken(UTILS.getRequest());
- if(dbUser.ConfirmForgetAdd(email, token)) {
- EMAIL.Send(email, 2, UTILS.BuildUrl(UTILS.getHeaderString("host"), "confirm", token));
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_SUCCESS);
- } else {
- Error();
- }
- } else {
- Error();
- }
- } else {
- Error();
- }
- } else {
- Error();
- }
- } else {
- Parameters();
- }
- } else {
- Error();
- }
- }
- private void Facebook() throws Exception {
- if(!AUTH) {
- JSONObject data = UTILS.getParamJSONObject("data");
- if (!data.isEmpty()) {
- if (data.containsKey("email")) {
- if (dbUser.CheckUserByEmail(data.getString("email")) <= 0) {
- result = Register(true);
- if(result.containsKey("id")) {
- result = Login((JSONObject) result.get("data"), true);
- }
- } else {
- result = Login(data, true);
- }
- } else {
- Parameters();
- }
- } else {
- Parameters();
- }
- } else {
- Error();
- }
- }
- private void GetInfo() throws Exception {
- if(AUTH) {
- if (ID > 0) {
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_SUCCESS);
- result.put("info", dbUser.GetUserInfo(ID));
- } else {
- Parameters();
- }
- } else {
- Authentication();
- }
- }
- private void GetDate() throws Exception {
- if(AUTH) {
- if (ID > 0) {
- String date = UTILS.getParamString("date");
- if(!date.isEmpty()) {
- result.put("coins", dbUser.GetUserCoins(ID));
- result.put("cday", dbUser.GetUserCoinsOnDay(ID, date));
- result.put("data", dbUser.GetUserTableDataOnDate(ID, date));
- //GetWebDateData(date);
- //GetWebPerson(dbUser.GetUserGender(ID));
- ShopGetUserProducts();
- } else {
- Parameters();
- }
- } else {
- Parameters();
- }
- } else {
- Authentication();
- }
- }
- private void GetDay(String date) throws Exception {
- if (AUTH) {
- if (!date.isEmpty()) {
- GetWebDateData(date);
- } else {
- Parameters();
- }
- } else {
- Authentication();
- }
- }
- private void GetWeek(String start) throws Exception {
- if (AUTH) {
- Calendar c = Calendar.getInstance();
- c.add(Calendar.DAY_OF_MONTH, -7);
- String end = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
- if (!start.isEmpty() && !end.isEmpty()) {
- result.put("data", ConvertTableDataToObject(dbUser.GetUserTableDataOnWeek(ID, start, end)));
- } else {
- Parameters();
- }
- } else {
- Authentication();
- }
- }
- private void GetMonth(String start) throws Exception {
- if (AUTH) {
- Calendar c = Calendar.getInstance();
- c.add(Calendar.DAY_OF_MONTH, -30);
- String end = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
- if (!start.isEmpty() && !end.isEmpty()) {
- result.put("data", ConvertTableDataToObject(dbUser.GetUserTableDataOnMonth(ID, start, end)));
- } else {
- Parameters();
- }
- } else {
- Authentication();
- }
- }
- private void GetInventory() throws Exception {
- ShopGetUserProducts();
- }
- private void GetCurrentClothes() throws Exception {
- }
- private void UpdateInfo() throws Exception {
- if(AUTH) {
- JSONObject data = UTILS.getParamJSONObject("data");
- if(!data.isEmpty()) {
- boolean success = false;
- if(data.containsKey("additions")) {
- JSONObject additions = (JSONObject) data.get("additions");
- data.remove("additions");
- String values = "";
- for (Object o : data.keySet()) {
- String key = (String) o;
- values += key + "='" + data.get(key) + "',";
- }
- values = values.substring(0, values.lastIndexOf(","));
- //System.out.println(values);
- LOGGER.info(values);
- dbUser.UpdateUserInfo(ID, values);
- JSONObject last = dbUser.GetLastUserRow(ID);
- last.remove("id");
- if(!last.isEmpty()) {
- //int gender = ;
- boolean change = false;
- CheckAddition(additions, dbUser.GetUserGender(ID));
- for (Object o : additions.keySet()) {
- String key = (String) o;
- if(last.containsKey(key)) {
- if(!last.getString(key).equals(additions.getString(key))) {
- last.replace(key, additions.getString(key));
- change=true;
- }
- }
- }
- if(change) {
- dbUser.AddAdditions(ID, last);
- }
- }
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_SUCCESS);
- result.put(BitStep.TYPE_MESSAGE, "Информация успешно обновлена");
- } else {
- Parameters();
- }
- } else {
- Parameters();
- }
- } else {
- Authentication();
- }
- }
- private void UpdatePassword() throws Exception {
- if(AUTH) {
- JSONObject data = UTILS.getParamJSONObject("data");
- if (!data.isEmpty()) {
- /*if (data.containsKey("p0") && data.containsKey("p1") && data.containsKey("p2")) {
- String p0 = data.getString("p0");
- String p1 = data.getString("p1");
- String p2 = data.getString("p2");
- if (!p0.isEmpty()) {
- if (!p1.isEmpty()) {
- if (!p2.isEmpty()) {
- if (p0.matches(BitStep.PASSWORD_REGEXP)) {
- if (p1.matches(BitStep.PASSWORD_REGEXP)) {
- if (p1.equals(p2)) {
- String email = dbUser.GetUserField(ID, "email");
- if(!email.isEmpty()) {
- p0 = HASHES.hashPassword(email, p0);
- p1 = HASHES.hashPassword(email, p1);
- if (dbUser.CheckPassword(ID, p0, p1)) {
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_SUCCESS);
- result.put(BitStep.TYPE_MESSAGE, "Пароль успешно обновлен");
- } else {
- Error();
- }
- } else {
- Error();
- }
- } else {
- result.put("p2", "Пароли не совпадают");
- }
- } else {
- result.put("p1", "Пароль не соответствует требованиям");
- }
- } else {
- result.put("p20", "Пароль не соответствует требованиям");
- }
- } else {
- result.put("p2", "Поле не может быть пустым");
- }
- } else {
- result.put("p1", "Поле не может быть пустым");
- }
- } else {
- result.put("p0", "Поле не может быть пустым");
- }
- }*/
- } else {
- Parameters();
- }
- } else {
- Authentication();
- }
- }
- private void AddSteps() throws Exception {
- if (MOBILE) {
- if(AUTH) {
- JSONObject data = UTILS.getParamJSONObject("data");
- /*System.out.println("execute - Add steps");
- System.out.println();*/
- LOGGER.info("Execute - Add steps");
- LOGGER.info("USERID - "+ID);
- LOGGER.info("data - " + data.toString());
- if (data.size() > 0) {
- JSONObject output = new JSONObject();
- JSONObject cPerson = dbUser.GetCurrentPerson(ID);
- JSONObject nPerson = dbUser.GetUserNextPerson(ID);
- String cDate = BitStep.GetDateMySql(Calendar.getInstance());
- dbUser.RemoveAdditions(ID, cDate);
- int coins = dbUser.GetUserCoins(ID)/*, weight = dbUser.GetUserWeight(ID)*/;
- //String gender = dbUser.GetUserField(ID, "gender");
- JSONObject last = dbUser.GetLastUserRow(ID);
- last.remove("id");
- if(!last.isEmpty()) {
- for (Object date : data.keySet()) {
- int maxsteps = cPerson.getInt("maxcoin")*BitStep.USER_STEPS_ONE_COIN;
- JSONArray aDate = (JSONArray) data.get(date);
- JSONArray toOut = new JSONArray();
- int dCoins = dbUser.GetUserCoinsOnDay(ID, date.toString());
- if(coins > 0) {
- coins -= dCoins;
- }
- int tCoins=0;
- for (Object day : aDate) {
- JSONObject oDay = (JSONObject) day;
- int lSteps = last.getInt("steps");
- int steps = oDay.getInt("steps");
- last.replace("coin", CountCoins(steps, maxsteps));
- last.replace("date", date);
- last.replace("time", oDay.getString("time"));
- last.replace("steps", steps);
- last.replace("calories", oDay.getInt("calories"));
- last.replace("complete", Complete(steps, (nPerson.getInt("steps")/nPerson.getInt("days"))));
- /*System.out.println("last - "+last.toJSONString());
- System.out.println("coin - "+coins+" lSteps - "+lSteps+" steps - "+steps+"\n");*/
- LOGGER.info("last - "+last.toJSONString());
- LOGGER.info("coin - "+coins+" lSteps - "+lSteps+" steps - "+steps);
- JSONObject row = dbUser.GetUserRowByDateTime(ID, date.toString(), oDay.getString("time"));
- LOGGER.info("Existing row - "+row.toJSONString());
- //System.out.println("Existing row - "+row.toJSONString());
- if(row.isEmpty()) {
- LOGGER.info("Add row");
- //System.out.println("Add row");
- if(dbUser.AddAdditions(ID, last)) {
- toOut.add(last.clone());
- }
- } else {
- LOGGER.info("Update row");
- //System.out.println("Update row");
- if(dbUser.UpdateUserRow(ID, row.getInt("id"), last)){
- toOut.add(last.clone());
- }
- }
- tCoins = last.getInt("coin");
- }
- coins+=tCoins;
- if(CheckPerson(cPerson, nPerson)) {
- //System.out.println("next person");
- cPerson = dbUser.GetCurrentPerson(ID);
- nPerson = dbUser.GetUserNextPerson(ID);
- result.put("person", cPerson.getInt("id"));
- last.replace("person_id", dbUser.GetUserPersonID(ID));
- } else {
- //System.err.println("Conditions, for new person, do not fit\n");
- LOGGER.error("Conditions, for new person, do not fit");
- }
- output.put(date, toOut);
- }
- if(dbUser.SetUserCoins(ID, coins)) {
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_SUCCESS);
- result.put("formatted", output);
- result.put("coins", coins);
- result.put("weekends", dbUser.GetUserWeekends(ID));
- result.put("tcoins", dbUser.GetUserCoinOnDate(ID, BitStep.GetDateMySql(Calendar.getInstance())));
- //result.replace("person", dbUser.GetUserPersonData(result.getInt("person")));
- result.put("cPerson", cPerson);
- result.put("nPerson", nPerson);
- ShopGetUserProducts();
- } else {
- Error();
- }
- } else {
- Error();
- }
- } else {
- Parameters();
- }
- LOGGER.error("Execute end - Add steps");
- //System.out.println("execute end - Add steps");
- } else {
- Authentication();
- }
- } else {
- Error();
- }
- }
- private void UpdateSteps() throws Exception {
- if (MOBILE) {
- if (AUTH) {
- JSONObject data = UTILS.getParamJSONObject("data");
- LOGGER.info("USERID - "+ID);
- LOGGER.info(data.toJSONString());
- //System.out.println(data.toString());
- if (!data.isEmpty()) {
- boolean exist = true;
- int coins = dbUser.GetUserCoins(ID);
- JSONObject cPerson = dbUser.GetCurrentPerson(ID);
- JSONObject nPerson = dbUser.GetUserNextPerson(ID);
- JSONObject cDate = dbUser.GetUserRowByDateTime(ID, data.getString("date"), data.getString("time"));
- if (cDate.isEmpty()) {
- LOGGER.info("Row not found. Get last row");
- exist = false;
- cDate = dbUser.GetLastUserRow(ID);
- }
- coins -= cDate.getInt("coin");
- int row_id = cDate.getInt("id");
- cDate.remove("id");
- for (Object o : data.keySet()) {
- cDate.replace(o, data.get(o));
- }
- cDate.replace("coin", CountCoins(data.getInt("steps"), cPerson.getInt("maxcoin") * BitStep.USER_STEPS_ONE_COIN));
- coins += cDate.getInt("coin");
- cDate.replace("complete", Complete(data.getInt("steps"), (nPerson.getInt("steps") / nPerson.getInt("days"))));
- cDate.replace("calories", data.getInt("calories"));
- if (exist?dbUser.UpdateUserRow(ID, row_id, cDate):dbUser.AddAdditions(ID, cDate)) {
- if (dbUser.SetUserCoins(ID, coins)) {
- result.put(BitStep.TYPE_STATUS, BitStep.TYPE_SUCCESS);
- result.put("coins", coins);
- result.put("formatted", cDate);
- result.put("weekends", dbUser.GetUserWeekends(ID));
- result.put("tcoins", dbUser.GetUserCoinOnDate(ID, BitStep.GetDateMySql(Calendar.getInstance())));
- CheckPerson(cPerson, nPerson);
- ShopGetUserProducts();
- result.put("cPerson", cPerson);
- result.put("nPerson", nPerson);
- } else {
- Error();
- }
- } else {
- Error();
- }
- /*} else {
- Error("Row not found");
- }*/
- } else {
- Error();
- }
- } else {
- Authentication();
- }
- } else {
- Error();
- }
- }
- private void ShopBuy() {
- if(AUTH) {
- } else {
- Authentication();
- }
- }
- /*private void ShopGetAllProducts() throws Exception {
- if(AUTH) {
- result.put("products", dbShop.GetAllClothList(dbUser.GetUserGender(ID)));
- GetProductsImages((JSONArray) result.get("products"));
- } else {
- Authentication();
- }
- }*/
- private void ShopGetUserProducts() throws Exception {
- if(AUTH) {
- result.put("person", dbUser.GetUserPersonID(ID));
- result.put("clothes", dbShop.GetUserList(ID));
- GetProductsImages((JSONArray) result.get("clothes"));
- } else {
- Authentication();
- }
- }
- private void ShopGetClothProducts() throws Exception {
- if(isAuth()) {
- result.put("products", dbShop.GetAllClothList(/*dbUser.GetUserGender(ID))*/));
- GetProductsImages((JSONArray) result.get("products"));
- } else {
- Authentication();
- }
- }
- private void ShopGetPersonProducts() throws Exception {
- if(isAuth()) {
- result.put("products", dbShop.GetAllPersonList());
- } else {
- Authentication();
- }
- }
- private void ShopGetWeekendsProducts() throws Exception {
- if(isAuth()) {
- result.put("products", dbShop.GetAllPersonList());
- } else {
- Authentication();
- }
- }
- private void ShopGetCoinsProducts() throws Exception {
- if(isAuth()) {
- result.put("products", dbShop.GetAllPersonList());
- } else {
- Authentication();
- }
- }
- private void ShopGetVipProduct() throws Exception {
- if(isAuth()) {
- result.put("products", dbShop.GetAllPersonList());
- } else {
- Authentication();
- }
- }
- private void ShopBuyCloth() throws SQLException {
- if(isAuth()) {
- int CLOTHID = UTILS.getParamInt("id");
- if(CLOTHID > 0) {
- JSONObject product = dbShop.GetClothData(CLOTHID);
- if(!product.isEmpty()) {
- if(!dbShop.CheckClothIsBought(ID, CLOTHID)) {
- int orderid = dbShop.AddOrder(ID, CLOTHID, "cloth", "Покупка вещи");
- if(orderid > 0) {
- HashMap params = new HashMap();
- params.put("action", "pay");
- params.put("amount", product.getInt("price"));
- params.put("currency", BitStep.SHOP_CURRENCY);
- params.put("language", "ru");
- params.put("sandbox", "1");
- params.put("server_url", UTILS.getDomain()+"/liqpay");
- params.put("description", "Покупка товара "+product.getString("label"));
- params.put("order_id", orderid);
- params.put("version", "3");
- params.put("sender_first_name", dbUser.GetUserField(ID, "firstname"));
- params.put("sender_last_name", dbUser.GetUserField(ID, "lastname"));
- params.put("product_name", product.getString("label"));
- params.put("customer", ID);
- LiqPay liqpay = new LiqPay(BitStep.SHOP_PUBLIC_KEY, BitStep.SHOP_PRIVATE_KEY);
- result.put("html", liqpay.cnb_form(params));
- } else {
- Error();
- }
- } else {
- Error("Вещь уже куплена.");
- }
- } else {
- Parameters();
- }
- } else {
- Error();
- }
- } else {
- Authentication();
- }
- }
- private void ShopBuyPerson() throws SQLException {
- if(isAuth()) {
- int PRODUCTID = UTILS.getParamInt("id");
- if(PRODUCTID>0) {
- JSONObject product = dbShop.GetPersonData(PRODUCTID);
- if(!product.isEmpty()) {
- boolean access = true;
- if(product.getString("name").equals("vip")) {
- if(dbUser.UserIsVip(ID)) {
- access = false;
- }
- }
- if(access) {
- int orderid = dbShop.AddOrder(ID, PRODUCTID, "person", ("Покупка "+product.getString("label")));
- if(orderid > 0) {
- HashMap params = new HashMap();
- params.put("action", "pay");
- params.put("amount", product.getInt("price"));
- params.put("currency", BitStep.SHOP_CURRENCY);
- params.put("language", "ru");
- params.put("sandbox", "1");
- params.put("server_url", UTILS.getDomain()+"/liqpay");
- params.put("description", "Покупка товара "+product.getString("label")+". Количество "+product.getInt("count"));
- params.put("order_id", orderid);
- params.put("version", "3");
- params.put("sender_first_name", dbUser.GetUserField(ID, "firstname"));
- params.put("sender_last_name", dbUser.GetUserField(ID, "lastname"));
- params.put("product_name", product.getString("label"));
- params.put("customer", ID);
- LiqPay liqpay = new LiqPay(BitStep.SHOP_PUBLIC_KEY, BitStep.SHOP_PRIVATE_KEY);
- result.put("html", liqpay.cnb_form(params));
- } else {
- Error();
- }
- } else {
- Error("Пользователь уже имеет статус vip");
- }
- } else {
- Error();
- }
- } else {
- Error();
- }
- } else {
- Authentication();
- }
- }
- private void GetPartners() throws Exception {
- if(isAuth()) {
- JSONArray parners = dbUser.GetAllPartners();
- for(Object p: parners) {
- JSONObject partner = (JSONObject) p;
- String name = partner.getString("company");
- if(!name.isEmpty()) {
- File image = FindFile(new File(UTILS.getRoot()+SEPARATOR+ PARTNERS_DIR+SEPARATOR), name);
- if(image!=null) {
- partner.replace("company", UTILS.getLocalIp()+SEPARATOR+ PARTNERS_DIR+SEPARATOR+image.getName());
- }
- }
- }
- result.put("partners", parners);
- } else {
- Error();
- }
- }
- private void GetWeb() throws Exception {
- if(isAuth()) {
- int GENDER = dbUser.GetUserGender(ID);
- GetWebPerson(GENDER);
- result.put("coins", dbUser.GetUserCoins(ID));
- result.put("tCoins", dbUser.GetUserCoinOnDate(ID, BitStep.GetDateMySql(Calendar.getInstance())));
- GetWebDateData(BitStep.GetDateMySql(Calendar.getInstance()));
- String path = SEPARATOR+PERSON_DIR+SEPARATOR+((JSONObject)result.get("person")).getInt("id")+SEPARATOR+PARTNERS_DIR+SEPARATOR+GENDER;
- JSONArray partners = new JSONArray();
- File pFiels = new File(UTILS.getRoot()+path);
- if(pFiels.exists()&&pFiels.isDirectory()) {
- for(File p: pFiels.listFiles()) {
- partners.add(path+SEPARATOR+p.getName());
- }
- }
- result.put("pPartners", partners);
- GetPartners();
- GetResults();
- } else {
- Authentication();
- }
- }
- private void GetResults() throws Exception {
- if(isAuth()) {
- result.put("wins", 0);
- result.put("wUsed", dbUser.GetUserUsedWeekends(ID));
- JSONArray dates = dbUser.GetUserDates(ID);
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(simpleDateFormat.parse(dates.get(0).toString()));
- int count = 0;
- for (int i=1; i<dates.size(); i++) {
- calendar.add(Calendar.DATE, -1);
- String currentDate = simpleDateFormat.format(calendar.getTime());
- //System.out.println(currentDate+" -> "+dates.get(i));
- if (currentDate.equals(dates.get(i))) {
- count++;
- }
- }
- result.put("days", count);
- CheckAchievements();
- result.put("achievements", dbUser.GetAchievements(ID));
- if(!MOBILE) {
- SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd");
- Calendar c = Calendar.getInstance();
- String start = dFormat.format(c.getTime());
- c.add(Calendar.DATE, -6);
- dates = dbUser.GetMiddleTableData(ID, start, dFormat.format(c.getTime()));
- int mSteps=0, mCalories=0, mCoins=0;
- for(Object d: dates) {
- JSONObject date = (JSONObject) d;
- mSteps+=date.getInt("steps");
- mCalories+=date.getInt("calories");
- mCoins+=date.getInt("coin");
- }
- //result.put("data", dates);
- result.put("mSteps", dates.size() > 0 ?(mSteps/dates.size()): 0);
- result.put("mCalories", dates.size() > 0 ?(mCalories/dates.size()): 0);
- result.put("mCoins", dates.size() > 0 ?(mCoins/dates.size()): 0);
- }
- } else {
- Authentication();
- }
- }
- /* STATIC METHODS */
- private void CheckAchievements() throws Exception {
- JSONArray all = dbUser.GetAllAchievements();
- if(!all.isEmpty()) {
- boolean set = false;
- int steps = dbUser.GetUserAllCountSteps(ID);
- for(Object a: all) {
- JSONObject ach = (JSONObject) a;
- if(ach.getString("type").equals("s")) {
- if(steps>=ach.getInt("value")&&!set) {
- set=true;
- dbUser.SetUserAchievement(ID, ach.getString("type"), ach.getInt("id"));
- }
- }
- }
- }
- }
- private void UserUpdateDeviceAndPush(int USERID) throws Exception {
- String device = UTILS.getHeaderString("user-agent");
- //System.out.println("Headers - "+UTILS.getHeaders().toJSONString());
- if(device.contains("iOS")) {
- device = "iOS";
- } else if(device.contains("Android")){
- device = "Android";
- }
- dbUser.UserUpdateDeviceAndPush(USERID, device, UTILS.getParamString("push"));
- }
- private void GetWebPerson(int GENDER) throws SQLException {
- JSONObject person = dbUser.GetUserPersonData(dbUser.GetUserPersonID(ID));
- result.put("person", person);
- result.put("pImage", SEPARATOR+PERSON_DIR+SEPARATOR+person.getInt("id")+SEPARATOR+GENDER+SEPARATOR+"person.png");
- }
- private void GetWebDateData(String DATE) throws SQLException {
- JSONArray dataOnDate = dbUser.GetUserTableDataOnDate(ID, DATE);
- JSONObject gSteps = new JSONObject();
- JSONObject gCalories = new JSONObject();
- JSONObject gCoins = new JSONObject();
- for(Object d: dataOnDate) {
- JSONObject date = (JSONObject) d;
- gSteps.put(date.getString("time"), date.getString("steps"));
- gCalories.put(date.getString("time"), date.getString("calories"));
- gCoins.put(date.getString("time"), date.getString("coin"));
- }
- result.put("gSteps", gSteps);
- result.put("gCalories", gCalories);
- result.put("gCoins", gCoins);
- JSONObject lastOnDate = new JSONObject();
- if(dataOnDate.size() > 0) {
- lastOnDate = (JSONObject) dataOnDate.get(dataOnDate.size()-1);
- }
- JSONObject circle = new JSONObject();
- circle.put("steps", !lastOnDate.isEmpty() ? lastOnDate.getInt("steps"):0);
- circle.put("calories", !lastOnDate.isEmpty() ? lastOnDate.getInt("calories"):0);
- circle.put("coin", !lastOnDate.isEmpty() ? lastOnDate.getInt("coin"):0);
- result.put("circle", circle);
- GetWebPerson(dbUser.GetUserGender(ID));
- }
- private JSONObject CheckAuthData(JSONObject data, boolean fb) {
- JSONObject errors = new JSONObject();
- String e = data.getString("email");
- String p = data.getString("password");
- if (e == null || e.isEmpty()) {
- errors.put("email", "Поле не может быть пустым");
- }
- if(!fb) {
- if (p == null || p.isEmpty()) {
- errors.put("password", "Поле не может быть пустым");
- }
- }
- if (errors.isEmpty()) {
- if (!e.matches(BitStep.EMAIL_REGEXP) || (!fb&&!p.matches(BitStep.PASSWORD_REGEXP))) {
- errors.put("error", "E-Mail или пароль неверны");
- }
- }
- if(!errors.isEmpty()) {
- data.put(BitStep.TYPE_TEXT_ERROR, errors);
- }
- return data;
- }
- private JSONObject CheckRegisterData(JSONObject data, boolean fb) {
- JSONObject error = new JSONObject();
- String email = data.getString("email");
- String p1 = data.getString("p1");
- String p2 = data.getString("p2");
- if (!data.containsKey("firstname") || data.getString("firstname").isEmpty()) {
- error.put("firstname", "Поле не может быть пустым");
- }
- if (!data.containsKey("lastname") || data.getString("lastname").isEmpty()) {
- error.put("lastname", "Поле не может быть пустым");
- }
- if (email == null || email.isEmpty()) {
- error.put("email", "Поле не может быть пустым");
- }
- if(!fb) {
- if (p1 == null || p1.isEmpty()) {
- error.put("p1", "Поле не может быть пустым");
- }
- if (p2 == null || p2.isEmpty()) {
- error.put("p2", "Поле не может быть пустым");
- }
- }
- if (error.isEmpty()) {
- if (!email.matches(BitStep.EMAIL_REGEXP)) {
- error.put("email", "Пожалуйста, введите корректный Email");
- }
- if(!fb) {
- if (!p1.matches(BitStep.PASSWORD_REGEXP)) {
- error.put("p1", "Пароль не соотвецтвует требованиям");
- }
- if (!p2.equals(p1)) {
- error.put("p2", "Пароли не совпадают");
- }
- }
- }
- if(!data.containsKey("gender") || data.getString("gender").isEmpty()) {
- error.put("gender", "Пол не задан");
- }
- if(!error.isEmpty()) {
- data.put(BitStep.TYPE_TEXT_ERROR, error);
- }
- return data;
- }
- private JSONObject CheckAddition(JSONObject data, int gender) {
- if(data.containsKey("weight") && data.containsKey("growth")) {
- if(data.getInt("weight") <= 0) {
- if(gender==1) {
- data.replace("weight", BitStep.DEFAULT_USER_WEIGHT_MALE);
- } else if(gender==2) {
- data.replace("weight", BitStep.DEFAULT_USER_WEIGHT_FEMALE);
- }
- }
- if(data.getInt("growth") <= 0) {
- if(gender==1) {
- data.replace("growth", BitStep.DEFAULT_USER_GROWTH_MALE);
- } else if(gender==2) {
- data.replace("growth", BitStep.DEFAULT_USER_GROWTH_FEMALE);
- }
- }
- }
- /*String[] time = ;
- if(Integer.parseInt(time[1])<=30) {
- time[1] = "00";
- } else if(Integer.parseInt(time[1])>30) {
- int i = Integer.parseInt(time[0]);
- time[0] = String.valueOf(++i);
- time[1] = "00";
- }*/
- data.replace("time", data.getString("time").split(":")[0]+":00:00");
- return data;
- }
- private JSONObject GetEmptyAdditions(int gender) {
- JSONObject additions = new JSONObject();
- additions.put("date", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
- additions.put("time", new SimpleDateFormat("HH:mm:ss").format(new Date()));
- additions.put("calories", 0);
- additions.put("steps", 0);
- additions.put("coin", 0);
- additions.put("visited", 0);
- additions.put("complete", 0);
- additions.put("weekend", 0);
- additions = CheckAddition(additions, gender);
- return additions;
- }
- private int CountCoins(int steps, int maxsteps) {
- return steps <= maxsteps?Math.round(steps/2000):0;
- }
- private int Complete(int steps, int dSteps) {
- return steps >= dSteps?1:0;
- }
- private boolean CheckPerson(JSONObject cPerson, JSONObject nPerson) throws Exception {
- //System.out.println();
- LOGGER.info("Start Check Person");
- boolean status = false;
- JSONArray dates = dbUser.GetUserPersonDates(ID, cPerson.getInt("id"));
- if(!dates.isEmpty()) {
- LOGGER.info("Available dates - "+dates.toJSONString());
- //System.out.println("Available dates - "+dates.toJSONString());
- if(dates.size() >= nPerson.getInt("days")) {
- if(DatesSequence(dates, nPerson.getInt("days"))) {
- status = dbUser.SetUserPerson(ID, nPerson.getInt("id"));
- if(status) {
- LOGGER.info("User, ID - " + ID + " has new person - " + nPerson.getInt("id"));
- //System.out.println();
- }
- } else {
- LOGGER.info("Empty");
- //System.out.println();
- }
- } else {
- LOGGER.info("Empty");
- //System.out.println("Empty");
- }
- } else {
- LOGGER.info("Empty");
- //System.out.println();
- }
- LOGGER.info("End Check Person");
- //System.out.println();
- return status;
- }
- private boolean DatesSequence(JSONArray dates, int count) throws Exception {
- int complete = 1;
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(simpleDateFormat.parse(dates.get(0).toString()));
- for (int i=1; i<dates.size(); i++) {
- calendar.add(Calendar.DATE, -1);
- String currentDate = simpleDateFormat.format(calendar.getTime());
- LOGGER.info(currentDate+" -> "+dates.get(i));
- if (currentDate.equals(dates.get(i))) {
- complete++;
- LOGGER.info("++ " + complete);
- } else {
- LOGGER.info("BREAK");
- break;
- }
- }
- LOGGER.info("COMPLETE COUNT - "+complete+" COUNT - "+count);
- return complete >=count;
- }
- private void GetProductsImages(JSONArray products) throws SQLException {
- int pid = dbUser.GetUserPersonID(ID);
- int gender = dbUser.GetUserGender(ID);
- for(Object c: products) {
- JSONObject product = (JSONObject) c;
- int id = product.getInt("id");
- String path = PERSON_DIR+SEPARATOR+pid+SEPARATOR+gender+SEPARATOR;
- File image = FindFile(new File(UTILS.getRoot()+path), String.valueOf(id));
- if(image!=null&&image.exists()) {
- product.put("image", path+image.getName());
- } else {
- product.put("image", "");
- }
- }
- }
- private File FindFile(File dir, String name) {
- File[] list = dir.listFiles();
- if (list != null) {
- for (File f : list) {
- if (f.isFile() && GetFileName(f).equals(name)) {
- return f;
- }
- }
- }
- return null;
- }
- private String GetFileName(File file) {
- return file.getName().substring(0, file.getName().lastIndexOf("."));
- }
- private String GetFileExt(File file) {
- return file.getName().substring(file.getName().indexOf("."), file.getName().length());
- }
- private JSONObject ConvertTableDataToObject(JSONArray input) {
- JSONObject data = new JSONObject();
- for(Object o: input) {
- JSONObject obj = (JSONObject) o;
- Object date = obj.get("date");
- if(!data.containsKey(date)) {
- data.put(date, new JSONArray());
- }
- JSONArray arr = (JSONArray) data.get(date);
- arr.add(obj);
- }
- return data;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement