]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
link show comments by default flag between the UI and the DB
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / MobileLedgerProfile.java
1 /*
2  * Copyright © 2019 Damyan Ivanov.
3  * This file is part of MoLe.
4  * MoLe is free software: you can distribute it and/or modify it
5  * under the term of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your opinion), any later version.
8  *
9  * MoLe is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License terms for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
16  */
17
18 package net.ktnx.mobileledger.model;
19
20 import android.content.res.Resources;
21 import android.database.Cursor;
22 import android.database.sqlite.SQLiteDatabase;
23 import android.util.SparseArray;
24
25 import androidx.annotation.NonNull;
26 import androidx.annotation.Nullable;
27
28 import net.ktnx.mobileledger.App;
29 import net.ktnx.mobileledger.R;
30 import net.ktnx.mobileledger.async.DbOpQueue;
31 import net.ktnx.mobileledger.async.SendTransactionTask;
32 import net.ktnx.mobileledger.utils.Globals;
33 import net.ktnx.mobileledger.utils.Logger;
34 import net.ktnx.mobileledger.utils.MLDB;
35 import net.ktnx.mobileledger.utils.Misc;
36
37 import java.util.ArrayList;
38 import java.util.Date;
39 import java.util.List;
40 import java.util.Locale;
41 import java.util.UUID;
42
43 import static net.ktnx.mobileledger.utils.Logger.debug;
44
45 public final class MobileLedgerProfile {
46     // N.B. when adding new fields, update the copy-constructor below
47     private String uuid;
48     private String name;
49     private boolean permitPosting;
50     private boolean showCommentsByDefault;
51     private boolean showCommodityByDefault;
52     private String defaultCommodity;
53     private String preferredAccountsFilter;
54     private String url;
55     private boolean authEnabled;
56     private String authUserName;
57     private String authPassword;
58     private int themeHue;
59     private int orderNo = -1;
60     // N.B. when adding new fields, update the copy-constructor below
61     private FutureDates futureDates = FutureDates.None;
62     private SendTransactionTask.API apiVersion = SendTransactionTask.API.auto;
63     public MobileLedgerProfile() {
64         this.uuid = String.valueOf(UUID.randomUUID());
65     }
66     public MobileLedgerProfile(String uuid) {
67         this.uuid = uuid;
68     }
69     public MobileLedgerProfile(MobileLedgerProfile origin) {
70         uuid = origin.uuid;
71         name = origin.name;
72         permitPosting = origin.permitPosting;
73         showCommentsByDefault = origin.showCommentsByDefault;
74         showCommodityByDefault = origin.showCommodityByDefault;
75         preferredAccountsFilter = origin.preferredAccountsFilter;
76         url = origin.url;
77         authEnabled = origin.authEnabled;
78         authUserName = origin.authUserName;
79         authPassword = origin.authPassword;
80         themeHue = origin.themeHue;
81         orderNo = origin.orderNo;
82         futureDates = origin.futureDates;
83         apiVersion = origin.apiVersion;
84         defaultCommodity = origin.defaultCommodity;
85     }
86     // loads all profiles into Data.profiles
87     // returns the profile with the given UUID
88     public static MobileLedgerProfile loadAllFromDB(String currentProfileUUID) {
89         MobileLedgerProfile result = null;
90         ArrayList<MobileLedgerProfile> list = new ArrayList<>();
91         SQLiteDatabase db = App.getDatabase();
92         try (Cursor cursor = db.rawQuery("SELECT uuid, name, url, use_authentication, auth_user, " +
93                                          "auth_password, permit_posting, theme, order_no, " +
94                                          "preferred_accounts_filter, future_dates, api_version, " +
95                                          "show_commodity_by_default, default_commodity, " +
96                                          "show_comments_by_default FROM " +
97                                          "profiles order by order_no", null))
98         {
99             while (cursor.moveToNext()) {
100                 MobileLedgerProfile item = new MobileLedgerProfile(cursor.getString(0));
101                 item.setName(cursor.getString(1));
102                 item.setUrl(cursor.getString(2));
103                 item.setAuthEnabled(cursor.getInt(3) == 1);
104                 item.setAuthUserName(cursor.getString(4));
105                 item.setAuthPassword(cursor.getString(5));
106                 item.setPostingPermitted(cursor.getInt(6) == 1);
107                 item.setThemeId(cursor.getInt(7));
108                 item.orderNo = cursor.getInt(8);
109                 item.setPreferredAccountsFilter(cursor.getString(9));
110                 item.setFutureDates(cursor.getInt(10));
111                 item.setApiVersion(cursor.getInt(11));
112                 item.setShowCommodityByDefault(cursor.getInt(12) == 1);
113                 item.setDefaultCommodity(cursor.getString(13));
114                 item.setShowCommentsByDefault(cursor.getInt(14) == 1);
115                 list.add(item);
116                 if (item.getUuid()
117                         .equals(currentProfileUUID))
118                     result = item;
119             }
120         }
121         Data.profiles.setValue(list);
122         return result;
123     }
124     public static void storeProfilesOrder() {
125         SQLiteDatabase db = App.getDatabase();
126         db.beginTransactionNonExclusive();
127         try {
128             int orderNo = 0;
129             for (MobileLedgerProfile p : Data.profiles.getValue()) {
130                 db.execSQL("update profiles set order_no=? where uuid=?",
131                         new Object[]{orderNo, p.getUuid()});
132                 p.orderNo = orderNo;
133                 orderNo++;
134             }
135             db.setTransactionSuccessful();
136         }
137         finally {
138             db.endTransaction();
139         }
140     }
141     public boolean getShowCommentsByDefault() {
142         return showCommentsByDefault;
143     }
144     public void setShowCommentsByDefault(boolean newValue) {
145         this.showCommentsByDefault = newValue;
146     }
147     public boolean getShowCommodityByDefault() {
148         return showCommodityByDefault;
149     }
150     public void setShowCommodityByDefault(boolean showCommodityByDefault) {
151         this.showCommodityByDefault = showCommodityByDefault;
152     }
153     public String getDefaultCommodity() {
154         return defaultCommodity;
155     }
156     public void setDefaultCommodity(String defaultCommodity) {
157         this.defaultCommodity = defaultCommodity;
158     }
159     public void setDefaultCommodity(CharSequence defaultCommodity) {
160         if (defaultCommodity == null)
161             this.defaultCommodity = null;
162         else
163             this.defaultCommodity = String.valueOf(defaultCommodity);
164     }
165     public SendTransactionTask.API getApiVersion() {
166         return apiVersion;
167     }
168     public void setApiVersion(SendTransactionTask.API apiVersion) {
169         this.apiVersion = apiVersion;
170     }
171     public void setApiVersion(int apiVersion) {
172         this.apiVersion = SendTransactionTask.API.valueOf(apiVersion);
173     }
174     public FutureDates getFutureDates() {
175         return futureDates;
176     }
177     public void setFutureDates(int anInt) {
178         futureDates = FutureDates.valueOf(anInt);
179     }
180     public void setFutureDates(FutureDates futureDates) {
181         this.futureDates = futureDates;
182     }
183     public String getPreferredAccountsFilter() {
184         return preferredAccountsFilter;
185     }
186     public void setPreferredAccountsFilter(String preferredAccountsFilter) {
187         this.preferredAccountsFilter = preferredAccountsFilter;
188     }
189     public void setPreferredAccountsFilter(CharSequence preferredAccountsFilter) {
190         setPreferredAccountsFilter(String.valueOf(preferredAccountsFilter));
191     }
192     public boolean isPostingPermitted() {
193         return permitPosting;
194     }
195     public void setPostingPermitted(boolean permitPosting) {
196         this.permitPosting = permitPosting;
197     }
198     public String getUuid() {
199         return uuid;
200     }
201     public String getName() {
202         return name;
203     }
204     public void setName(CharSequence text) {
205         setName(String.valueOf(text));
206     }
207     public void setName(String name) {
208         this.name = name;
209     }
210     public String getUrl() {
211         return url;
212     }
213     public void setUrl(CharSequence text) {
214         setUrl(String.valueOf(text));
215     }
216     public void setUrl(String url) {
217         this.url = url;
218     }
219     public boolean isAuthEnabled() {
220         return authEnabled;
221     }
222     public void setAuthEnabled(boolean authEnabled) {
223         this.authEnabled = authEnabled;
224     }
225     public String getAuthUserName() {
226         return authUserName;
227     }
228     public void setAuthUserName(CharSequence text) {
229         setAuthUserName(String.valueOf(text));
230     }
231     public void setAuthUserName(String authUserName) {
232         this.authUserName = authUserName;
233     }
234     public String getAuthPassword() {
235         return authPassword;
236     }
237     public void setAuthPassword(CharSequence text) {
238         setAuthPassword(String.valueOf(text));
239     }
240     public void setAuthPassword(String authPassword) {
241         this.authPassword = authPassword;
242     }
243     public void storeInDB() {
244         SQLiteDatabase db = App.getDatabase();
245         db.beginTransactionNonExclusive();
246         try {
247 //            debug("profiles", String.format("Storing profile in DB: uuid=%s, name=%s, " +
248 //                                            "url=%s, permit_posting=%s, authEnabled=%s, " +
249 //                                            "themeHue=%d", uuid, name, url,
250 //                    permitPosting ? "TRUE" : "FALSE", authEnabled ? "TRUE" : "FALSE", themeHue));
251             db.execSQL("REPLACE INTO profiles(uuid, name, permit_posting, url, " +
252                        "use_authentication, auth_user, auth_password, theme, order_no, " +
253                        "preferred_accounts_filter, future_dates, api_version, " +
254                        "show_commodity_by_default, default_commodity, show_comments_by_default) " +
255                        "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
256                     new Object[]{uuid, name, permitPosting, url, authEnabled,
257                                  authEnabled ? authUserName : null,
258                                  authEnabled ? authPassword : null, themeHue, orderNo,
259                                  preferredAccountsFilter, futureDates.toInt(), apiVersion.toInt(),
260                                  showCommodityByDefault, defaultCommodity, showCommentsByDefault
261                     });
262             db.setTransactionSuccessful();
263         }
264         finally {
265             db.endTransaction();
266         }
267     }
268     public void storeAccount(SQLiteDatabase db, LedgerAccount acc) {
269         // replace into is a bad idea because it would reset hidden to its default value
270         // we like the default, but for new accounts only
271         db.execSQL("update accounts set level = ?, keep = 1, hidden=?, expanded=? " +
272                    "where profile=? and name = ?",
273                 new Object[]{acc.getLevel(), acc.isHiddenByStar(), acc.isExpanded(), uuid,
274                              acc.getName()
275                 });
276         db.execSQL("insert into accounts(profile, name, name_upper, parent_name, level, hidden, " +
277                    "expanded, keep) " + "select ?,?,?,?,?,?,?,1 where (select changes() = 0)",
278                 new Object[]{uuid, acc.getName(), acc.getName().toUpperCase(), acc.getParentName(),
279                              acc.getLevel(), acc.isHiddenByStar(), acc.isExpanded()
280                 });
281 //        debug("accounts", String.format("Stored account '%s' in DB [%s]", acc.getName(), uuid));
282     }
283     public void storeAccountValue(SQLiteDatabase db, String name, String currency, Float amount) {
284         db.execSQL("replace into account_values(profile, account, " +
285                    "currency, value, keep) values(?, ?, ?, ?, 1);",
286                 new Object[]{uuid, name, Misc.emptyIsNull(currency), amount});
287     }
288     public void storeTransaction(SQLiteDatabase db, LedgerTransaction tr) {
289         tr.fillDataHash();
290         db.execSQL("DELETE from transactions WHERE profile=? and id=?",
291                 new Object[]{uuid, tr.getId()});
292         db.execSQL("DELETE from transaction_accounts WHERE profile = ? and transaction_id=?",
293                 new Object[]{uuid, tr.getId()});
294
295         db.execSQL("INSERT INTO transactions(profile, id, date, description, data_hash, keep) " +
296                    "values(?,?,?,?,?,1)",
297                 new Object[]{uuid, tr.getId(), Globals.formatLedgerDate(tr.getDate()),
298                              tr.getDescription(), tr.getDataHash()
299                 });
300
301         for (LedgerTransactionAccount item : tr.getAccounts()) {
302             db.execSQL("INSERT INTO transaction_accounts(profile, transaction_id, " +
303                        "account_name, amount, currency, comment) values(?, ?, ?, ?, ?, ?)",
304                     new Object[]{uuid, tr.getId(), item.getAccountName(), item.getAmount(),
305                                  Misc.nullIsEmpty(item.getCurrency()), item.getComment()
306                     });
307         }
308 //        debug("profile", String.format("Transaction %d stored", tr.getId()));
309     }
310     public String getOption(String name, String default_value) {
311         SQLiteDatabase db = App.getDatabase();
312         try (Cursor cursor = db.rawQuery("select value from options where profile = ? and name=?",
313                 new String[]{uuid, name}))
314         {
315             if (cursor.moveToFirst()) {
316                 String result = cursor.getString(0);
317
318                 if (result == null) {
319                     debug("profile", "returning default value for " + name);
320                     result = default_value;
321                 }
322                 else
323                     debug("profile", String.format("option %s=%s", name, result));
324
325                 return result;
326             }
327             else
328                 return default_value;
329         }
330         catch (Exception e) {
331             debug("db", "returning default value for " + name, e);
332             return default_value;
333         }
334     }
335     public long getLongOption(String name, long default_value) {
336         long longResult;
337         String result = getOption(name, "");
338         if ((result == null) || result.isEmpty()) {
339             debug("profile", String.format("Returning default value for option %s", name));
340             longResult = default_value;
341         }
342         else {
343             try {
344                 longResult = Long.parseLong(result);
345                 debug("profile", String.format("option %s=%s", name, result));
346             }
347             catch (Exception e) {
348                 debug("profile", String.format("Returning default value for option %s", name), e);
349                 longResult = default_value;
350             }
351         }
352
353         return longResult;
354     }
355     public void setOption(String name, String value) {
356         debug("profile", String.format("setting option %s=%s", name, value));
357         DbOpQueue.add("insert or replace into options(profile, name, value) values(?, ?, ?);",
358                 new String[]{uuid, name, value});
359     }
360     public void setLongOption(String name, long value) {
361         setOption(name, String.valueOf(value));
362     }
363     public void removeFromDB() {
364         SQLiteDatabase db = App.getDatabase();
365         debug("db", String.format("removing profile %s from DB", uuid));
366         db.beginTransactionNonExclusive();
367         try {
368             Object[] uuid_param = new Object[]{uuid};
369             db.execSQL("delete from profiles where uuid=?", uuid_param);
370             db.execSQL("delete from accounts where profile=?", uuid_param);
371             db.execSQL("delete from account_values where profile=?", uuid_param);
372             db.execSQL("delete from transactions where profile=?", uuid_param);
373             db.execSQL("delete from transaction_accounts where profile=?", uuid_param);
374             db.execSQL("delete from options where profile=?", uuid_param);
375             db.setTransactionSuccessful();
376         }
377         finally {
378             db.endTransaction();
379         }
380     }
381     @NonNull
382     public LedgerAccount loadAccount(String name) {
383         SQLiteDatabase db = App.getDatabase();
384         return loadAccount(db, name);
385     }
386     @Nullable
387     public LedgerAccount tryLoadAccount(String acct_name) {
388         SQLiteDatabase db = App.getDatabase();
389         return tryLoadAccount(db, acct_name);
390     }
391     @NonNull
392     public LedgerAccount loadAccount(SQLiteDatabase db, String accName) {
393         LedgerAccount acc = tryLoadAccount(db, accName);
394
395         if (acc == null)
396             throw new RuntimeException("Unable to load account with name " + accName);
397
398         return acc;
399     }
400     @Nullable
401     public LedgerAccount tryLoadAccount(SQLiteDatabase db, String accName) {
402         try (Cursor cursor = db.rawQuery(
403                 "SELECT a.hidden, a.expanded, (select 1 from accounts a2 " +
404                 "where a2.profile = a.profile and a2.name like a.name||':%' limit 1) " +
405                 "FROM accounts a WHERE a.profile = ? and a.name=?", new String[]{uuid, accName}))
406         {
407             if (cursor.moveToFirst()) {
408                 LedgerAccount acc = new LedgerAccount(accName);
409                 acc.setHiddenByStar(cursor.getInt(0) == 1);
410                 acc.setExpanded(cursor.getInt(1) == 1);
411                 acc.setHasSubAccounts(cursor.getInt(2) == 1);
412
413                 try (Cursor c2 = db.rawQuery(
414                         "SELECT value, currency FROM account_values WHERE profile = ? " +
415                         "AND account = ?", new String[]{uuid, accName}))
416                 {
417                     while (c2.moveToNext()) {
418                         acc.addAmount(c2.getFloat(0), c2.getString(1));
419                     }
420                 }
421
422                 return acc;
423             }
424             return null;
425         }
426     }
427     public LedgerTransaction loadTransaction(int transactionId) {
428         LedgerTransaction tr = new LedgerTransaction(transactionId, this.uuid);
429         tr.loadData(App.getDatabase());
430
431         return tr;
432     }
433     public int getThemeHue() {
434 //        debug("profile", String.format("Profile.getThemeHue() returning %d", themeHue));
435         return this.themeHue;
436     }
437     public void setThemeHue(Object o) {
438         setThemeId(Integer.parseInt(String.valueOf(o)));
439     }
440     public void setThemeId(int themeHue) {
441 //        debug("profile", String.format("Profile.setThemeHue(%d) called", themeHue));
442         this.themeHue = themeHue;
443     }
444     public void markTransactionsAsNotPresent(SQLiteDatabase db) {
445         db.execSQL("UPDATE transactions set keep=0 where profile=?", new String[]{uuid});
446
447     }
448     public void markAccountsAsNotPresent(SQLiteDatabase db) {
449         db.execSQL("update account_values set keep=0 where profile=?;", new String[]{uuid});
450         db.execSQL("update accounts set keep=0 where profile=?;", new String[]{uuid});
451
452     }
453     public void deleteNotPresentAccounts(SQLiteDatabase db) {
454         db.execSQL("delete from account_values where keep=0 and profile=?", new String[]{uuid});
455         db.execSQL("delete from accounts where keep=0 and profile=?", new String[]{uuid});
456     }
457     public void markTransactionAsPresent(SQLiteDatabase db, LedgerTransaction transaction) {
458         db.execSQL("UPDATE transactions SET keep = 1 WHERE profile = ? and id=?",
459                 new Object[]{uuid, transaction.getId()
460                 });
461     }
462     public void markTransactionsBeforeTransactionAsPresent(SQLiteDatabase db,
463                                                            LedgerTransaction transaction) {
464         db.execSQL("UPDATE transactions SET keep=1 WHERE profile = ? and id < ?",
465                 new Object[]{uuid, transaction.getId()
466                 });
467
468     }
469     public void deleteNotPresentTransactions(SQLiteDatabase db) {
470         db.execSQL("DELETE FROM transactions WHERE profile=? AND keep = 0", new String[]{uuid});
471     }
472     public void setLastUpdateStamp() {
473         debug("db", "Updating transaction value stamp");
474         Date now = new Date();
475         setLongOption(MLDB.OPT_LAST_SCRAPE, now.getTime());
476         Data.lastUpdateDate.postValue(now);
477     }
478     public List<LedgerAccount> loadChildAccountsOf(LedgerAccount acc) {
479         List<LedgerAccount> result = new ArrayList<>();
480         SQLiteDatabase db = App.getDatabase();
481         try (Cursor c = db.rawQuery(
482                 "SELECT a.name FROM accounts a WHERE a.profile = ? and a.name like ?||':%'",
483                 new String[]{uuid, acc.getName()}))
484         {
485             while (c.moveToNext()) {
486                 LedgerAccount a = loadAccount(db, c.getString(0));
487                 result.add(a);
488             }
489         }
490
491         return result;
492     }
493     public List<LedgerAccount> loadVisibleChildAccountsOf(LedgerAccount acc) {
494         List<LedgerAccount> result = new ArrayList<>();
495         ArrayList<LedgerAccount> visibleList = new ArrayList<>();
496         visibleList.add(acc);
497
498         SQLiteDatabase db = App.getDatabase();
499         try (Cursor c = db.rawQuery(
500                 "SELECT a.name FROM accounts a WHERE a.profile = ? and a.name like ?||':%'",
501                 new String[]{uuid, acc.getName()}))
502         {
503             while (c.moveToNext()) {
504                 LedgerAccount a = loadAccount(db, c.getString(0));
505                 if (a.isVisible(visibleList)) {
506                     result.add(a);
507                     visibleList.add(a);
508                 }
509             }
510         }
511
512         return result;
513     }
514     public void wipeAllData() {
515         SQLiteDatabase db = App.getDatabase();
516         db.beginTransaction();
517         try {
518             String[] pUuid = new String[]{uuid};
519             db.execSQL("delete from options where profile=?", pUuid);
520             db.execSQL("delete from accounts where profile=?", pUuid);
521             db.execSQL("delete from account_values where profile=?", pUuid);
522             db.execSQL("delete from transactions where profile=?", pUuid);
523             db.execSQL("delete from transaction_accounts where profile=?", pUuid);
524             db.setTransactionSuccessful();
525             Logger.debug("wipe", String.format(Locale.ENGLISH, "Profile %s wiped out", pUuid[0]));
526         }
527         finally {
528             db.endTransaction();
529         }
530     }
531     public List<Currency> getCurrencies() {
532         SQLiteDatabase db = App.getDatabase();
533
534         ArrayList<Currency> result = new ArrayList<>();
535
536         try (Cursor c = db.rawQuery("SELECT c.id, c.name, c.position, c.has_gap FROM currencies c",
537                 new String[]{}))
538         {
539             while (c.moveToNext()) {
540                 Currency currency = new Currency(c.getInt(0), c.getString(1),
541                         Currency.Position.valueOf(c.getInt(2)), c.getInt(3) == 1);
542                 result.add(currency);
543             }
544         }
545
546         return result;
547     }
548     Currency loadCurrencyByName(String name) {
549         SQLiteDatabase db = App.getDatabase();
550         Currency result = tryLoadCurrencyByName(db, name);
551         if (result == null)
552             throw new RuntimeException(String.format("Unable to load currency '%s'", name));
553         return result;
554     }
555     private Currency tryLoadCurrencyByName(SQLiteDatabase db, String name) {
556         try (Cursor cursor = db.rawQuery(
557                 "SELECT c.id, c.name, c.position, c.has_gap FROM currencies c WHERE c.name=?",
558                 new String[]{name}))
559         {
560             if (cursor.moveToFirst()) {
561                 return new Currency(cursor.getInt(0), cursor.getString(1),
562                         Currency.Position.valueOf(cursor.getInt(2)), cursor.getInt(3) == 1);
563             }
564             return null;
565         }
566     }
567     public enum FutureDates {
568         None(0), OneWeek(7), TwoWeeks(14), OneMonth(30), TwoMonths(60), ThreeMonths(90),
569         SixMonths(180), OneYear(365), All(-1);
570         private static SparseArray<FutureDates> map = new SparseArray<>();
571
572         static {
573             for (FutureDates item : FutureDates.values()) {
574                 map.put(item.value, item);
575             }
576         }
577
578         private int value;
579         FutureDates(int value) {
580             this.value = value;
581         }
582         public static FutureDates valueOf(int i) {
583             return map.get(i, None);
584         }
585         public int toInt() {
586             return this.value;
587         }
588         public String getText(Resources resources) {
589             switch (value) {
590                 case 7:
591                     return resources.getString(R.string.future_dates_7);
592                 case 14:
593                     return resources.getString(R.string.future_dates_14);
594                 case 30:
595                     return resources.getString(R.string.future_dates_30);
596                 case 60:
597                     return resources.getString(R.string.future_dates_60);
598                 case 90:
599                     return resources.getString(R.string.future_dates_90);
600                 case 180:
601                     return resources.getString(R.string.future_dates_180);
602                 case 365:
603                     return resources.getString(R.string.future_dates_365);
604                 case -1:
605                     return resources.getString(R.string.future_dates_all);
606                 default:
607                     return resources.getString(R.string.future_dates_none);
608             }
609         }
610     }
611 }