/src/mpv5/db/common/Context.java
Java | 1786 lines | 1302 code | 187 blank | 297 comment | 105 complexity | f3af97773d126fe701ae97555a0d949a MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
1package mpv5.db.common; 2 3import java.io.Serializable; 4import java.util.ArrayList; 5import java.util.Arrays; 6import java.util.HashMap; 7import java.util.List; 8import java.util.Map; 9import mpv5.db.objects.Account; 10import mpv5.db.objects.ActivityList; 11import mpv5.db.objects.ActivityListSubItem; 12import mpv5.db.objects.Address; 13import mpv5.db.objects.Company; 14import mpv5.db.objects.Contact; 15import mpv5.db.objects.Conversation; 16import mpv5.db.objects.Expense; 17import mpv5.db.objects.Favourite; 18import mpv5.db.objects.FileToContact; 19import mpv5.db.objects.Group; 20import mpv5.db.objects.HistoryItem; 21import mpv5.db.objects.UserProperty; 22import mpv5.db.objects.Schedule; 23import mpv5.db.objects.FileToItem; 24import mpv5.db.objects.FileToProduct; 25import mpv5.db.objects.Item; 26import mpv5.db.objects.MailMessage; 27import mpv5.db.objects.MassprintRules; 28import mpv5.db.objects.Product; 29import mpv5.db.objects.ProductGroup; 30import mpv5.db.objects.ProductList; 31import mpv5.db.objects.ProductOrder; 32import mpv5.db.objects.ProductOrderSubItem; 33import mpv5.db.objects.ProductPrice; 34import mpv5.db.objects.ProductlistSubItem; 35import mpv5.db.objects.ProductsToSuppliers; 36import mpv5.db.objects.Reminder; 37import mpv5.db.objects.Revenue; 38import mpv5.db.objects.ScheduleTypes; 39import mpv5.db.objects.Stage; 40import mpv5.db.objects.SubItem; 41import mpv5.db.objects.Tax; 42import mpv5.db.objects.Template; 43import mpv5.pluginhandling.Plugin; 44import mpv5.db.objects.User; 45import mpv5.db.objects.ValueProperty; 46import mpv5.db.objects.WSContactsMapping; 47import mpv5.db.objects.WSItemsMapping; 48import mpv5.db.objects.WebShop; 49import mpv5.logging.Log; 50import mpv5.pluginhandling.UserPlugin; 51import mpv5.usermanagement.MPSecurityManager; 52import mpv5.utils.text.RandomText; 53import mpv5.utils.xml.XMLReader; 54 55/** 56 * 57 * Context controls Database Queries for all native MP {@link DatabaseObject}s 58 */ 59public class Context implements Serializable { 60 61 //********** tablenames **************************************************** 62 public static String IDENTITY_CONTACTS = "contacts"; 63 public static String IDENTITY_USERS = "users"; 64 public static String IDENTITY_ITEMS = "items"; 65 public static String IDENTITY_SUBITEMS = "subitems"; 66 public static String IDENTITY_LANGUAGES = "languages"; 67 public static String IDENTITY_COUNTRIES = "countries"; 68 public static String IDENTITY_PRODUCTS = "products"; 69 public static String IDENTITY_FILES = "files"; 70 public static String IDENTITY_LOCK = "tablelock"; 71 public static String IDENTITY_FAVS = "favourites"; 72 public static String IDENTITY_ADDRESS = "addresses"; 73 public static String IDENTITY_GROUPS = "groups"; 74 public static String IDENTITY_PGROUPS = "productgroups"; 75 public static String IDENTITY_SCHEDULE = "schedule"; 76 public static String IDENTITY_SCHEDULE_TYPES = "scheduletypes"; 77 public static String IDENTITY_HISTORY = "history"; 78 public static String IDENTITY_FILES_TO_CONTACTS = "filestocontacts"; 79 public static String IDENTITY_FILES_TO_PRODUCTS = "filestoproducts"; 80 public static String IDENTITY_SEARCHINDEX = "searchindex"; 81 public static String IDENTITY_PLUGINS_TO_USERS = "pluginstousers"; 82 public static String IDENTITY_TEMPLATES_TO_USERS = "templatestousers"; 83 public static String IDENTITY_PLUGINS = "plugins"; 84 public static String IDENTITY_PROPERTIES_TO_USERS = "userproperties"; 85 public static String IDENTITY_ACCOUNTS = "accounts"; 86 public static String IDENTITY_ITEMS_TO_ACCOUNTS = "itemstoaccounts"; 87 public static String IDENTITY_PRODUCTSLISTITEMS = "productlistitems"; 88 public static String IDENTITY_PRODUCTSLIST = "productlists"; 89 public static String IDENTITY_FORMATS_T_USERS = "formatstousers"; 90 public static String IDENTITY_FILES_TO_ITEMS = "filestoitems"; 91 public static String IDENTITY_MAIL = "mails"; 92 public static String IDENTITY_TAX = "tax"; 93 public static String IDENTITY_COMPANIES = "comps"; 94 public static String IDENTITY_GLOBALSETTINGS = "globalsettings"; 95 public static String IDENTITY_WEBSHOPS = "webshops"; 96 public static String IDENTITY_WSMAPPING = "wscontactsmapping"; 97 public static String IDENTITY_WSIMAPPING = "wsitemsmapping"; 98 public static String IDENTITY_TEMPLATES = "templates"; 99 public static String IDENTITY_REMINDERS = "reminders"; 100 public static String IDENTITY_STAGES = "stages"; 101 public static String IDENTITY_REVENUE = "revenues"; 102 public static String IDENTITY_EXPENSE = "expenses"; 103 public static String IDENTITY_PRODUCTS_TO_SUPPLIERS = "productstosuppliers"; 104 public static String IDENTITY_VALUE_PROPERTIES = "valueproperties"; 105 public static String IDENTITY_CONVERSATION = "conversations"; 106 public static String IDENTITY_PRODUCT_PRICES = "productprices"; 107 public static String IDENTITY_ACTIVITYLISTITEMS = "activitylistitems"; 108 public static String IDENTITY_ACTIVITYLIST = "activitylists"; 109 public static String IDENTITY_MASSPRINT = "massprintrules"; 110 public static String IDENTITY_PRODUCTORDER = "productorders"; 111 public static String IDENTITY_PRODUCTORDERSUBITEM = "productordersubitems"; 112 //********** identity classes ********************************************** 113 private static Class<Contact> IDENTITY_CONTACTS_CLASS = Contact.class; 114 private static Class<Address> IDENTITY_ADDRESS_CLASS = Address.class; 115 private static Class<User> IDENTITY_USERS_CLASS = User.class; 116 private static Class<Item> IDENTITY_ITEMS_CLASS = Item.class; 117 private static Class<FileToContact> IDENTITY_CONTACTS_FILES_CLASS = FileToContact.class; 118 private static Class<FileToItem> IDENTITY_ITEM_FILES_CLASS = FileToItem.class; 119 private static Class<HistoryItem> IDENTITY_HISTORY_ITEMS_CLASS = HistoryItem.class; 120 private static Class<SubItem> IDENTITY_SUBITEMS_CLASS = SubItem.class; 121 private static Class<UserPlugin> IDENTITY_USER_PLUGINS_CLASS = UserPlugin.class; 122 private static Class<Plugin> IDENTITY_PLUGINS_CLASS = Plugin.class; 123 private static Class<UserProperty> IDENTITY_PROPERTIES_CLASS = UserProperty.class; 124 private static Class<Account> IDENTITY_ACCOUNTS_CLASS = Account.class; 125 private static Class<ProductlistSubItem> IDENTITY_ITEMSLIST_CLASS = ProductlistSubItem.class; 126 private static Class<MailMessage> IDENTITY_MAILS_CLASS = MailMessage.class; 127 private static Class<Product> IDENTITY_PRODUCTS_CLASS = Product.class; 128 private static Class<Group> IDENTITY_GROUPS_CLASS = Group.class; 129 private static Class<Company> IDENTITY_COMPANY_CLASS = Company.class; 130 private static Class<ProductGroup> IDENTITY_PGROUPS_CLASS = ProductGroup.class; 131 private static Class<FileToProduct> IDENTITY_PRODUCTS_FILES_CLASS = FileToProduct.class; 132 private static Class<WebShop> IDENTITY_WEBSHOP_CLASS = WebShop.class; 133 private static Class<Template> IDENTITY_TEMPLATE_CLASS = Template.class; 134 private static Class<Reminder> IDENTITY_REMINDER_CLASS = Reminder.class; 135 private static Class<Stage> IDENTITY_STAGE_CLASS = Stage.class; 136 private static Class<ValueProperty> IDENTITY_VALUEPROPERTY_CLASS = ValueProperty.class; 137 private static Class<ProductPrice> IDENTITY_PRODUCTPRICE_CLASS = ProductPrice.class; 138 private static Class<Favourite> IDENTITY_FAVOURITE_CLASS = Favourite.class; 139 private static Class<Tax> IDENTITY_TAX_CLASS = Tax.class; 140 private static Class<WSContactsMapping> IDENTITY_WSCONTACTSMAPPING_CLASS = WSContactsMapping.class; 141 private static Class<WSItemsMapping> IDENTITY_WSITEMSMAPPING_CLASS = WSItemsMapping.class; 142 private static Class<Expense> IDENTITY_EXPENSE_CLASS = Expense.class; 143 private static Class<ProductList> IDENTITY_PRODUCTLIST_CLASS = ProductList.class; 144 private static Class<ProductsToSuppliers> IDENTITY_PRODUCTSTOSUPPLIERS_CLASS = ProductsToSuppliers.class; 145 private static Class<Conversation> IDENTITY_CONVERSATION_CLASS = Conversation.class; 146 private static Class<Schedule> IDENTITY_SCHEDULE_CLASS = Schedule.class; 147 private static Class<ScheduleTypes> IDENTITY_SCHEDULETYPES_CLASS = ScheduleTypes.class; 148 private static Class<ActivityListSubItem> IDENTITY_ACTIVITYITEMSLIST_CLASS = ActivityListSubItem.class; 149 private static Class<ActivityList> IDENTITY_ACTIVITYLIST_CLASS = ActivityList.class; 150 private static Class<MassprintRules> IDENTITY_MASSPRINT_CLASS = MassprintRules.class; 151 private static Class<ProductOrder> IDENTITY_PRODUCTORDER_CLASS = ProductOrder.class; 152 private static Class<ProductOrderSubItem> IDENTITY_PRODUCTORDERSUBITEM_CLASS = ProductOrderSubItem.class; 153 154 //********** unique constraints ******************************************* 155 public static String UNIQUECOLUMNS_USER = "cname"; 156 public static String UNIQUECOLUMNS_ITEMS = "cname"; 157 public static String UNIQUECOLUMNS_GROUPS = "cname"; 158 public static String UNIQUECOLUMNS_DEFAULT = "cname"; 159 public static String DETAIL_CONTACT_SEARCH = "prename,cname,street,city,country,notes"; 160 private static final long serialVersionUID = 1L; 161 162 //********** conditions **************************************************** 163 private boolean isCompany = false; 164 private boolean isCustomer = false; 165 private boolean isManufacturer = false; 166 private boolean isSupplier = false; 167 private Integer itemStatus = null; 168 private Integer itemType = null; 169 public static final String CONDITION_DEFAULT = "%%tablename%%" + "." + "IDS>0"; 170 public static final String CONDITION_CONTACTS_COMPANY = IDENTITY_CONTACTS + "." + "iscompany"; 171 public static final String CONDITION_CONTACTS_CUSTOMER = IDENTITY_CONTACTS + "." + "iscustomer"; 172 public static final String CONDITION_CONTACTS_MANUFACTURER = IDENTITY_CONTACTS + "." + "ismanufacturer"; 173 public static final String CONDITION_CONTACTS_SUPPLIER = IDENTITY_CONTACTS + "." + "issupplier"; 174 public static final String CONDITION_ITEMS_TYPE = IDENTITY_ITEMS + "." + "inttype"; 175 public static final String CONDITION_ITEMS_STATUS = IDENTITY_ITEMS + "." + "intstatus"; 176 //********** searchfields ************************************************** 177 public static final String SEARCH_NAME = "cname"; 178// public static final String SEARCH_CONTACT_NUMBER = "cnumber"; 179// public static final String SEARCH_CONTACT_CITY = "city"; 180 //********** defaults ****************************************************** 181 public static String DEFAULT_SUBID = "ids, cname"; 182 public static String DEFAULT_CONTACT_SEARCH = "ids, cnumber, cname, city, street"; 183 public static String DEFAULT_USER_SEARCH = "ids, cname, mail, lastlogdate"; 184 public static String DEFAULT_ITEM_SEARCH = "ids, cname, dateadded, netvalue"; 185 public static String DEFAULT_PRODUCT_SEARCH = "ids, cnumber, cname, description"; 186 public static String DEFAULT_ACTIVITYLIST_SEARCH = "DISTINCT ids,cname"; 187 public static String DEFAULT_PRODUCTSLIST_SEARCH = "DISTINCT ids,cname,description"; 188 //********** table fields ******************************************************** 189 public static String DETAILS_CONTACTS = IDENTITY_CONTACTS + "." + "IDS," + IDENTITY_CONTACTS + "." + "CNUMBER," 190 + IDENTITY_CONTACTS + "." + "TITLE," + IDENTITY_CONTACTS + "." + "PRENAME," + IDENTITY_CONTACTS + "." + "CNAME," 191 + IDENTITY_CONTACTS + "." + "STREET," + IDENTITY_CONTACTS + "." + "ZIP," + IDENTITY_CONTACTS + "." + "CITY," 192 + IDENTITY_CONTACTS + "." + "MAINPHONE," + IDENTITY_CONTACTS + "." + "FAX," + IDENTITY_CONTACTS + "." + "MOBILEPHONE," 193 + IDENTITY_CONTACTS + "." + "WORKPHONE," + IDENTITY_CONTACTS + "." + "COMPANY," + IDENTITY_CONTACTS + "." + "MAILADDRESS," 194 + IDENTITY_CONTACTS + "." + "WEBSITE," + IDENTITY_CONTACTS + "." + "NOTES," 195 + IDENTITY_CONTACTS + "." + "TAXNUMBER"; 196 public static String DETAILS_PRODUCTS = 197 IDENTITY_PRODUCTS + "." + "ids," 198 + IDENTITY_PRODUCTS + "." + "cnumber," 199 + IDENTITY_PRODUCTS + "." + "cname," 200 + IDENTITY_PRODUCTS + "." + "ean," 201 + IDENTITY_PRODUCTS + "." + "reference," 202 + IDENTITY_CONTACTS + "." + "cname," 203 + IDENTITY_GROUPS + "." + "cname," 204 + IDENTITY_PRODUCTS + "." + "internalnetvalue," 205 + IDENTITY_PRODUCTS + "." + "externalnetvalue," 206 + IDENTITY_PRODUCTS + "." + "stockvalue"; 207 public static String DETAILS_USERS = IDENTITY_USERS + "." + "IDS," + IDENTITY_USERS + "." + "CNAME," 208 + IDENTITY_USERS + "." + "fullname," 209 + IDENTITY_USERS + "." + "mail," 210 + IDENTITY_USERS + "." + "isenabled," 211 + IDENTITY_USERS + "." + "isloggedin"; 212 public static String DETAILS_ITEMS = 213 IDENTITY_ITEMS + "." + "IDS," 214 + IDENTITY_ITEMS + "." + "CNAME," 215 + IDENTITY_ITEMS + "." + "dateadded," 216 + IDENTITY_ITEMS + "." + "netvalue," 217 + IDENTITY_ITEMS + "." + "taxvalue, " 218 + IDENTITY_ITEMS + "." + "datetodo"; 219 public static String DETAILS_JOURNAL = Context.IDENTITY_ITEMS + "." + "IDS," + Context.IDENTITY_CONTACTS + "." + "cname," + Context.IDENTITY_CONTACTS + "." + "prename," + Context.IDENTITY_CONTACTS + "." + "street," + Context.IDENTITY_CONTACTS + "." + "city," + Context.IDENTITY_CONTACTS + "." + "country," + Context.IDENTITY_ITEMS + "." + "{date}," + Context.IDENTITY_GROUPS + "." + "CNAME," + Context.IDENTITY_ACCOUNTS + "." + "cname," + Context.IDENTITY_ITEMS + "." + "CNAME," + Context.IDENTITY_ITEMS + "." + "inttype," + Context.IDENTITY_ITEMS + "." + "intstatus," + Context.IDENTITY_ITEMS + "." + "netvalue," + Context.IDENTITY_ITEMS + "." + "taxvalue, (" + Context.IDENTITY_ITEMS + "." + "netvalue +" + Context.IDENTITY_ITEMS + "." + "taxvalue)"; 220 public static String DETAILS_JOURNAL2 = Context.IDENTITY_REVENUE + "." + "IDS," + Context.IDENTITY_GROUPS + "." + "reserve2," + Context.IDENTITY_GROUPS + "." + "reserve2," + Context.IDENTITY_GROUPS + "." + "reserve2," + Context.IDENTITY_GROUPS + "." + "reserve2," + Context.IDENTITY_GROUPS + "." + "reserve2," + Context.IDENTITY_REVENUE + "." + "dateadded," + Context.IDENTITY_GROUPS + "." + "CNAME," + Context.IDENTITY_ACCOUNTS + "." + "cname," + Context.IDENTITY_REVENUE + "." + "CNAME," + Context.IDENTITY_REVENUE + "." + "ids," + Context.IDENTITY_REVENUE + "." + "ispaid," + Context.IDENTITY_REVENUE + "." + "netvalue, (" + Context.IDENTITY_REVENUE + "." + "brutvalue-" + Context.IDENTITY_REVENUE + "." + "netvalue)," + Context.IDENTITY_REVENUE + "." + "brutvalue"; 221 public static String DETAILS_JOURNAL3 = Context.IDENTITY_EXPENSE + "." + "IDS," + Context.IDENTITY_GROUPS + "." + "reserve2," + Context.IDENTITY_GROUPS + "." + "reserve2," + Context.IDENTITY_GROUPS + "." + "reserve2," + Context.IDENTITY_GROUPS + "." + "reserve2," + Context.IDENTITY_GROUPS + "." + "reserve2," + Context.IDENTITY_EXPENSE + "." + "{date}," + Context.IDENTITY_GROUPS + "." + "CNAME," + Context.IDENTITY_ACCOUNTS + "." + "cname," + Context.IDENTITY_EXPENSE + "." + "CNAME," + Context.IDENTITY_EXPENSE + "." + "ids," + Context.IDENTITY_EXPENSE + "." + "ispaid," + Context.IDENTITY_EXPENSE + "." + "netvalue, (" + Context.IDENTITY_EXPENSE + "." + "brutvalue-" + Context.IDENTITY_EXPENSE + "." + "netvalue)," + Context.IDENTITY_EXPENSE + "." + "brutvalue"; 222 public static String DETAILS_HISTORY = getHistory().getDbIdentity() + ".ids, " + getHistory().getDbIdentity() + ".cname, " + getHistory().getDbIdentity() + ".username, " + Context.getGroup().getDbIdentity() + ".cname," + Context.getHistory().getDbIdentity() + ".dateadded"; 223 public static String DETAILS_FILES_TO_CONTACTS = Context.getFiles().getDbIdentity() + ".cname," + getFilesToContacts().getDbIdentity() + ".cname, " + Context.getFiles().getDbIdentity() + ".dateadded," + Context.getFilesToContacts().getDbIdentity() + ".description," + Context.getFilesToContacts().getDbIdentity() + ".intsize," + Context.getFilesToContacts().getDbIdentity() + ".mimetype"; 224 public static String DETAILS_FILES_TO_ITEMS = Context.getFiles().getDbIdentity() + ".cname," + getFilesToItems().getDbIdentity() + ".cname, " + Context.getFiles().getDbIdentity() + ".dateadded," + Context.getFilesToItems().getDbIdentity() + ".description," + Context.getFilesToItems().getDbIdentity() + ".intsize," + Context.getFilesToItems().getDbIdentity() + ".mimetype"; 225 public static String DETAILS_FILES_TO_PRODUCTS = Context.getFiles().getDbIdentity() + ".cname," + getFilesToProducts().getDbIdentity() + ".cname, " + Context.getFiles().getDbIdentity() + ".dateadded," + Context.getFilesToProducts().getDbIdentity() + ".description," + Context.getFilesToProducts().getDbIdentity() + ".intsize," + Context.getFilesToProducts().getDbIdentity() + ".mimetype"; 226 public static String DETAILS_MASSPRINT = 227 Context.IDENTITY_MASSPRINT + "." + "IDS," 228 + Context.IDENTITY_MASSPRINT + "." + "cname," 229 + Context.IDENTITY_MASSPRINT + "." + "inttype," 230 + Context.IDENTITY_MASSPRINT + "." + "dateadded"; 231// public static String DETAILS_FILES_TO_TEMPLATES = Context.getTemplate().getDbIdentity() + ".ids," + getTemplate().getDbIdentity() + ".cname, " + Context.getTemplate().getDbIdentity() + ".dateadded," + Context.getTemplate().getDbIdentity() + ".intsize," + Context.getTemplate().getDbIdentity() + ".mimetype"; 232// public static String DETAILS_TEMPLATES = Context.getTemplate().getDbIdentity() + ".ids," + getTemplate().getDbIdentity() + ".cname, " + Context.getTemplate().getDbIdentity() + ".mimetype," + " groups0.cname"; 233 private static final Map<String, String> FOREIGN_KEY_ALIASES = new HashMap<String, String>(); 234 235 /** 236 * Find an alias (eg originalproducstids is an alias for productsids in table subitems) 237 * @param context 238 * @param exct 239 * @return 240 */ 241 public static String getAliasFor(Context context, Context exct) { 242 if (FOREIGN_KEY_ALIASES.containsKey(context + "@" + exct)) { 243 return FOREIGN_KEY_ALIASES.get(context + "@" + exct); 244 } else { 245 return context.getDbIdentity(); 246 } 247 } 248 //************************************************************************** 249 250 /** 251 * Contexts which can have an export template 252 * @return 253 */ 254 public static ArrayList<Context> getTemplateableContexts() { 255 ArrayList<Context> list = new ArrayList<Context>(); 256 list.add(getItem(null, null)); 257 list.add(getInvoice()); 258 list.add(getOrder()); 259 list.add(getOffer()); 260 list.add(getProduct()); 261 list.add(getReminder()); 262 list.add(getActivityList()); 263 return list; 264 } 265 266 /** 267 * Contexts which are protected by the Securitymanager 268 * @return 269 */ 270 public static ArrayList<Context> getSecuredContexts() { 271 ArrayList<Context> list = new ArrayList<Context>(); 272 list.add(getContactsCompanies()); 273// list.add(getUser()); Needs to be non-secure, to update user details on close 274 list.add(getCustomer()); 275 list.add(getManufacturer()); 276 list.add(getSupplier()); 277 list.add(getAddress()); 278 list.add(getItem(null, null)); 279 list.add(getInvoice()); 280 list.add(getOrder()); 281 list.add(getOffer()); 282 list.add(getSchedule()); 283 list.add(getCountries()); 284 list.add(getContact()); 285 list.add(getProduct()); 286 list.add(getAccounts()); 287 list.add(getCompany()); 288 list.add(getWebShop()); 289 list.add(getTemplate()); 290 list.add(getReminder()); 291 list.add(getSubItem()); 292 list.add(getProductOrderSubitem()); 293 list.add(getProductOrder()); 294 list.add(getProductPrice()); 295 296 return list; 297 } 298 299 /** 300 * Contexts which can get cached 301 * @return 302 */ 303 public static ArrayList<Context> getCacheableContexts() { 304 return cacheableContexts; 305 } 306 private static ArrayList<Context> cacheableContexts = new ArrayList<Context>(Arrays.asList(new Context[]{ 307 getContact(), 308 getFavourite(), 309 getUser(), 310 getAddress(), 311 getItem(null, null), 312 getSubItem(), 313 getGroup(), 314 getSchedule(), 315 getFilesToContacts(), 316 getFilesToItems(), 317 getFilesToProducts(), 318 getProduct(), 319 getAccounts(), 320 getMessage(), 321 getProductListItems(), 322 getCompany(), 323 getWebShop(), 324 getTemplate(), 325 getReminder(), 326 getStage(), 327 getTaxes(), 328 getProductGroup(), 329 getProductPrice(), 330 getActivityListItems(), 331 getProductOrderSubitem(), 332 getProductOrder() 333 })); 334 335 /** 336 * Contexts which are groupable 337 * @return 338 */ 339 public static ArrayList<Context> getGroupableContexts() { 340 ArrayList<Context> list = new ArrayList<Context>(); 341 list.add(getContactsCompanies()); 342 list.add(getCustomer()); 343 list.add(getManufacturer()); 344 list.add(getSupplier()); 345 list.add(getItem(null, null)); 346 list.add(getInvoice()); 347 list.add(getOrder()); 348 list.add(getOffer()); 349 list.add(getSchedule()); 350 list.add(getContact()); 351 list.add(getProduct()); 352 list.add(getAccounts()); 353 list.add(getMessage()); 354 list.add(getProductListItems()); 355 list.add(getSearchIndex()); 356 list.add(getGlobalSettings()); 357 list.add(getCompany()); 358 list.add(getWebShop()); 359 list.add(getTemplate()); 360 list.add(getReminder()); 361 list.add(getStage()); 362 list.add(getExpense()); 363 list.add(getRevenue()); 364 list.add(getTaxes()); 365 list.add(getProductPrice()); 366 list.add(getActivityListItems()); 367 list.add(getProductOrderSubitem()); 368 list.add(getProductOrder()); 369 return list; 370 } 371 372 /** 373 * Contexts which can be moved to trash rather than delete 374 * @return 375 */ 376 public static ArrayList<Context> getTrashableContexts() { 377 ArrayList<Context> list = new ArrayList<Context>(); 378 list.add(getContactsCompanies()); 379 list.add(getCustomer()); 380 list.add(getManufacturer()); 381 list.add(getSupplier()); 382 list.add(getItem(null, null)); 383 list.add(getInvoice()); 384 list.add(getOrder()); 385 list.add(getOffer()); 386 list.add(getSubItem()); 387 list.add(getContact()); 388 list.add(getProduct()); 389 list.add(getFiles()); 390 list.add(getExpense()); 391 list.add(getRevenue()); 392 list.add(getActivityList()); 393 list.add(getProductOrderSubitem()); 394 list.add(getProductOrder()); 395 return list; 396 } 397 398 /** 399 * Contexts which are monitored by the History 400 * @return 401 */ 402 public static ArrayList<Context> getArchivableContexts() { 403 return getSecuredContexts(); 404 } 405 406 /** 407 * Contexts which can be used in a user's Search 408 * @return 409 */ 410 public static ArrayList<Context> getSearchableContexts() { 411 ArrayList<Context> list = new ArrayList<Context>(); 412 list.add(getSubItem()); 413 list.add(getItem()); 414 list.add(getSchedule()); 415 list.add(getContact()); 416 list.add(getProduct()); 417 list.add(getProductOrderSubitem()); 418 list.add(getProductOrder()); 419//// list.add(getAccounts()); 420 return list; 421 } 422 423 /** 424 * LOckable Contexts 425 * @return 426 */ 427 public static ArrayList<Context> getLockableContexts() { 428 ArrayList<Context> list = new ArrayList<Context>(); 429// list.add(getUser()); 430 list.add(getItem(null, null)); 431 list.add(getSchedule()); 432 list.add(getContact()); 433 list.add(getProduct()); 434 list.add(getContactsCompanies()); 435 list.add(getCustomer()); 436 list.add(getSupplier()); 437 list.add(getManufacturer()); 438 list.add(getWebShop()); 439 return list; 440 } 441 442 /** 443 * Importable Contexts 444 * @return 445 */ 446 public static ArrayList<Context> getImportableContexts() { 447 ArrayList<Context> list = new ArrayList<Context>(); 448 list.add(getItem(null, null)); 449 list.add(getMessage()); 450 list.add(getContact()); 451 list.add(getProduct()); 452 list.add(getAccounts()); 453 list.add(getGroup()); 454 return list; 455 } 456 457 /** 458 * 459 * @return All availbale contexts 460 */ 461 public static ArrayList<Context> getContexts() { 462 return allContexts; 463 } 464 /** 465 * A list of all available contexts 466 */ 467 private static ArrayList<Context> allContexts = new ArrayList<Context>(Arrays.asList(new Context[]{ 468 getContactsCompanies(), 469 getContact(), 470 getCustomer(), 471 getFavourite(), 472 getFiles(), 473 getLanguage(), 474 getLock(), 475 getManufacturer(), 476 getSupplier(), 477 getUser(), 478 getAddress(), 479 getItem(null, null), 480 getInvoice(), 481 getOrder(), 482 getOffer(), 483 getSubItem(), 484 getGroup(), 485 getSchedule(), 486 getFilesToContacts(), 487 getHistory(), 488 getCountries(), 489 getProduct(), 490 getPlugins(), 491 getPluginsToUsers(), 492 getTemplatesToUsers(), 493 getUserProperties(), 494 getAccounts(), 495 getItemsToAccounts(), 496 getMessage(), 497 getProductListItems(), 498 getFormats(), 499 getTaxes(), 500 getGlobalSettings(), 501 getCompany(), 502 getWebShop(), 503 getWebShopItemMapping(), 504 getWebShopContactMapping(), 505 getTemplate(), 506 getReminder(), 507 getStage(), 508 getProductlist(), 509 getExpense(), 510 getRevenue(), 511 getProductsToSuppliers(), 512 getValueProperties(), 513 getProductPrice(), 514 getMassprint(), 515 getProductOrderSubitem(), 516 getProductOrder() 517 })); 518// private String[] searchHeaders; 519 private volatile ArrayList<String[]> references = new ArrayList<String[]>(); 520 private boolean exclusiveConditionsAvailable = false; 521 private volatile String exclusiveCondition; 522 private volatile String uniqueColumns; 523 private volatile int id = -1; 524 525 /** 526 * Constructor now private 527 */ 528 private Context() { 529 } 530 531 /** 532 * Constructs a new Context with a random ID 533 * @param tablename The name of the table to use 534 * @param targetObjectClass The class of the {@link DatabaseObject} child to be used with this Context 535 * @param cacheable If true, the {@link DatabaseObject}s related to this context will be cached 536 * @param secured If true, the {@link DatabaseObject}s related to this context will be protected by the {@link MPSecurityManager} 537 * @param importable If true, the {@link DatabaseObject}s related to this context will be importable by the {@link XMLReader} 538 * @param lockable If true, the {@link DatabaseObject}s related to this context will be loackable to avoid concurrent access 539 * @param groupable If true, the {@link DatabaseObject}s related to this context will apply to a users group restriction 540 * @param trashable If true, the {@link DatabaseObject}s related to this context will be moved to the trashbin on delete 541 * @param archivable If true, actions on the {@link DatabaseObject}s related to this context will be monitored 542 */ 543 public Context(String tablename, Class targetObjectClass, boolean cacheable, 544 boolean secured, boolean importable, boolean lockable, boolean groupable, 545 boolean trashable, boolean archivable) { 546 setId(Integer.valueOf(RandomText.getNumberText())); 547 this.setSubID(DEFAULT_SUBID); 548 this.setDbIdentity(tablename); 549 this.setIdentityClass(targetObjectClass); 550 if (archivable) { 551 getArchivableContexts().add(this); 552 } 553 if (cacheable) { 554 getCacheableContexts().add(this); 555 } 556 if (secured) { 557 getSecuredContexts().add(this); 558 } 559 if (importable) { 560 getImportableContexts().add(this); 561 } 562 if (lockable) { 563 getLockableContexts().add(this); 564 } 565 if (groupable) { 566 getGroupableContexts().add(this); 567 } 568 if (trashable) { 569 getTrashableContexts().add(this); 570 } 571 if (archivable) { 572 getArchivableContexts().add(this); 573 } 574 } 575 576 /** 577 * Constructs a new Context with a random ID 578 * @param tablename The name of the table to use 579 * @param targetObjectClass The class of the {@link DatabaseObject} child to be used with this Context 580 */ 581 public Context(String tablename, Class targetObjectClass) { 582 setId(Integer.valueOf(RandomText.getNumberText())); 583 this.setSubID(DEFAULT_SUBID); 584 this.setDbIdentity(tablename); 585 this.setIdentityClass(targetObjectClass); 586 } 587 588 /** 589 * Constructs a new Context with a random ID 590 * @param targetObjectClass The tablename will be assumed from the Class' simple name 591 */ 592 public Context(Class targetObjectClass) { 593 this(targetObjectClass.getSimpleName(), targetObjectClass); 594 } 595 596 /** 597 * Constructs a new Context with a random ID. 598 * The tablename will be assumed from the targetObject's Class simple name 599 * @param targetObject 600 */ 601 public Context(DatabaseObject targetObject) { 602 setId(Integer.valueOf(RandomText.getNumberText())); 603 this.setSubID(DEFAULT_SUBID); 604 this.setDbIdentity(targetObject.getClass().getSimpleName()); 605 this.setIdentityClass(targetObject.getClass()); 606 } 607 /** 608 * A default, empty Context without id 609 */ 610 public static Context DEFAULT = new Context(); 611 private Class identityClass = null; 612 /* 613 * The DB Identity name - usually the table 614 */ 615 private String dbIdentity = null; 616 617 /* 618 * The DB Sub Identity name - maybe a column name 619 */ 620 private String subID = null; 621 622 /* 623 * The search default result columns 624 */ 625 private String defResultFields = null; 626 627 /** 628 * 629 * @return The unique constraints 630 */ 631 public String getUniqueColumns() { 632 return uniqueColumns; 633 } 634 635 /** 636 * 637 * @param customer 638 * @param supplier 639 * @param manufacturer 640 * @param company 641 */ 642 public void setContactConditions(boolean customer, boolean supplier, boolean manufacturer, boolean company) { 643 setCustomer(customer); 644 setSupplier(supplier); 645 setManufacturer(manufacturer); 646 setCompany(company); 647 } 648 649 /** 650 * Set conditions to get exclusive data (e.g. customer = false results in all data without any customer) 651 * @param customer 652 * @param supplier 653 * @param manufacturer 654 * @param company 655 */ 656 public void setExclusiveContactConditions(boolean customer, boolean supplier, boolean manufacturer, boolean company) { 657 658 String cond = " "; 659 boolean first = true; 660 661 if (customer) { 662 if (first) { 663 cond += "WHERE "; 664 } 665 first = false; 666 cond += " " + CONDITION_CONTACTS_CUSTOMER + "=1 AND "; 667 } else { 668 if (first) { 669 cond += "WHERE "; 670 } 671 first = false; 672 cond += " " + CONDITION_CONTACTS_CUSTOMER + "=0 AND "; 673 } 674 if (supplier) { 675 if (first) { 676 cond += "WHERE "; 677 } 678 first = false; 679 cond += " " + CONDITION_CONTACTS_SUPPLIER + "=1 AND "; 680 } else { 681 if (first) { 682 cond += "WHERE "; 683 } 684 first = false; 685 cond += " " + CONDITION_CONTACTS_SUPPLIER + "=0 AND "; 686 } 687 if (manufacturer) { 688 if (first) { 689 cond += "WHERE "; 690 } 691 first = false; 692 cond += " " + CONDITION_CONTACTS_MANUFACTURER + "=1 AND "; 693 } else { 694 if (first) { 695 cond += "WHERE "; 696 } 697 first = false; 698 cond += " " + CONDITION_CONTACTS_MANUFACTURER + "=0 AND "; 699 } 700 if (company) { 701 if (first) { 702 cond += "WHERE "; 703 } 704 first = false; 705 cond += " " + CONDITION_CONTACTS_COMPANY + "=1 AND "; 706 } else { 707 if (first) { 708 cond += "WHERE "; 709 } 710 first = false; 711 cond += " " + CONDITION_CONTACTS_COMPANY + "=0 AND "; 712 } 713 714 if (!first) { 715 cond = cond.substring(4, cond.length() - 4); 716 if (mpv5.db.objects.User.getCurrentUser().isGroupRestricted() && getGroupableContexts().contains(this)) { 717 cond += "AND (" + dbIdentity + "." + "GROUPSIDS = " + mpv5.db.objects.User.getCurrentUser().__getGroupsids() + " OR " + dbIdentity + "." + "GROUPSIDS = 1)"; 718 } 719 } else { 720 721 if (mpv5.db.objects.User.getCurrentUser().isGroupRestricted() && getGroupableContexts().contains(this)) { 722 cond = "WHERE (" + dbIdentity + "." + "GROUPSIDS = " + mpv5.db.objects.User.getCurrentUser().__getGroupsids() + " OR " + dbIdentity + "." + "GROUPSIDS = 1)"; 723 } else { 724 cond = "WHERE " + CONDITION_DEFAULT; 725 } 726 } 727 728 if (getTrashableContexts().contains(this)) { 729 cond += " AND " + getDbIdentity() + ".invisible = 0 "; 730 } 731 732 exclusiveCondition = cond; 733 } 734 735 /** 736 * 737 * @return DB condition string 738 */ 739 public String getConditions(boolean withInvisible) { 740 if (!exclusiveConditionsAvailable) { 741 String cond = " "; 742 boolean first = true; 743 if (isCompany()) { 744 if (first) { 745 cond += "("; 746 } 747 first = false; 748 cond += " " + CONDITION_CONTACTS_COMPANY + "=1 OR "; 749 } 750 if (isCustomer()) { 751 if (first) { 752 cond += "("; 753 } 754 first = false; 755 cond += " " + CONDITION_CONTACTS_CUSTOMER + "=1 OR "; 756 } 757 if (isManufacturer()) { 758 if (first) { 759 cond += "("; 760 } 761 first = false; 762 cond += " " + CONDITION_CONTACTS_MANUFACTURER + "=1 OR "; 763 } 764 if (isSupplier()) { 765 if (first) { 766 cond += "("; 767 } 768 first = false; 769 cond += " " + CONDITION_CONTACTS_SUPPLIER + "=1 OR "; 770 } 771 if (itemType != null) { 772 if (first) { 773 cond += "("; 774 775 } 776 first = false; 777 cond += " " + CONDITION_ITEMS_TYPE + "=" + getItemType() + " OR "; 778 } 779 if (itemStatus != null) { 780 if (first) { 781 cond += "("; 782 783 } 784 first = false; 785 cond += " " + CONDITION_ITEMS_STATUS + "=" + getItemStatus() + " OR "; 786 } 787 if (!first) { 788 cond = "WHERE" + cond.substring(0, cond.length() - 3) + ")"; 789 if (mpv5.db.objects.User.getCurrentUser().isGroupRestricted() && getGroupableContexts().contains(this)) { 790 cond += " AND (" + dbIdentity + "." + "GROUPSIDS = " + mpv5.db.objects.User.getCurrentUser().__getGroupsids() + " OR " + dbIdentity + "." + "GROUPSIDS = 1)"; 791 } 792 } else { 793 if (mpv5.db.objects.User.getCurrentUser().isGroupRestricted() && getGroupableContexts().contains(this)) { 794 cond = "WHERE (" + dbIdentity + "." + "GROUPSIDS = " + mpv5.db.objects.User.getCurrentUser().__getGroupsids() + " OR " + dbIdentity + "." + "GROUPSIDS = 1)"; 795 } else { 796 cond = "WHERE " + CONDITION_DEFAULT; 797 } 798 } 799 if (!withInvisible && getTrashableContexts().contains(this)) { 800 cond += " AND " + dbIdentity + ".invisible = 0 "; 801 } 802// if (!QueryHandler.isMatchingBraces(cond)) { 803// cond += ")"; 804// } 805 return cond; 806 } else { 807 return exclusiveCondition.toString(); 808 } 809 } 810 811 /** 812 * Generates a SQL String (WHERE clause) which can be used to implement multi-client capability.<br/> 813 * <br/> 814 * <b>If the current Context does not support grouping, or the current user is not Group restricted, this will return NULL.</b> 815 * @return 816 */ 817 public synchronized String getGroupRestrictionSQLString() { 818 if (mpv5.db.objects.User.getCurrentUser().isGroupRestricted() && getGroupableContexts().contains(this)) { 819 return " (" + dbIdentity + "." + "GROUPSIDS = " + mpv5.db.objects.User.getCurrentUser().__getGroupsids() + " OR " + dbIdentity + "." + "GROUPSIDS = 1)"; 820 } else { 821 return null; 822 } 823 } 824 825 /** 826 * Generates a SQL String (WHERE clause) which can be used to avoid having already trashed elements in the resulting data. 827 * 828 * @return " invisible = 0 " or NULL if Context is not trashable 829 */ 830 public synchronized String getNoTrashSQLString() { 831 if (getTrashableContexts().contains(this)) { 832 return " " + dbIdentity + ".invisible = 0 "; 833 } else { 834 return null; 835 } 836 } 837 838 /** 839 * Generates a SQL String (WHERE clause) which can be used to implement multi-client capability.<br/> 840 * <br/> 841 * <b>If the current Context does not support grouping, or the current user is not Group restricted, this will return NULL.</b> 842 * @param tableName 843 * @return 844 */ 845 public synchronized String getGroupRestrictionSQLString(String tableName) { 846 if (mpv5.db.objects.User.getCurrentUser().isGroupRestricted() && getGroupableContexts().contains(this)) { 847 return " (" + tableName + "." + "GROUPSIDS = " + mpv5.db.objects.User.getCurrentUser().__getGroupsids() + " OR " + tableName + "." + "GROUPSIDS = 1)"; 848 } else { 849 return null; 850 } 851 } 852 853 /** 854 * Generates a SQL String (WHERE clause) which can be used to avoid having already trashed elements in the resulting data. 855 * 856 * @param tableName 857 * @return " invisible = 0 " or NULL if Context is not trashable 858 */ 859 public synchronized String getNoTrashSQLString(String tableName) { 860 if (getTrashableContexts().contains(this)) { 861 return " " + tableName + ".invisible = 0 "; 862 } else { 863 return null; 864 } 865 } 866 867 /** 868 * Add MP specific conditions to a sql query 869 * @param query 870 * @return The query 871 */ 872 public synchronized String prepareSQLString(String query) { 873 874 if (getGroupRestrictionSQLString() != null) { 875 if (query.toUpperCase().contains("WHERE")) { 876 query = query + " AND" + getGroupRestrictionSQLString(); 877 } else { 878 query = query + " WHERE" + getGroupRestrictionSQLString(); 879 } 880 } 881 if (getNoTrashSQLString() != null) { 882 if (query.toUpperCase().contains("WHERE")) { 883 query = query + " AND" + getNoTrashSQLString(); 884 } else { 885 query = query + " WHERE" + getNoTrashSQLString(); 886 } 887 } 888 return query; 889 } 890 891 /** 892 * Add MP specific conditions to a sql query 893 * @param query 894 * @param tableName 895 * @return The query 896 */ 897 public synchronized String prepareSQLString(String query, String tableName) { 898 899 if (getGroupRestrictionSQLString(tableName) != null) { 900 if (query.toUpperCase().contains("WHERE")) { 901 query = query + " AND" + getGroupRestrictionSQLString(tableName); 902 } else { 903 query = query + " WHERE" + getGroupRestrictionSQLString(tableName); 904 } 905 } 906 if (getNoTrashSQLString(tableName) != null) { 907 if (query.toUpperCase().contains("WHERE")) { 908 query = query + " AND" + getNoTrashSQLString(tableName); 909 } else { 910 query = query + " WHERE" + getNoTrashSQLString(tableName); 911 } 912 } 913 return query; 914 } 915 916// /** 917// * Define the owner of this Context 918// * @param parentobject 919// */ 920// public void setOwner(DatabaseObject parentobject) { 921// this.parent = parentobject; 922// } 923 /** 924 * Remove all exclusive conditions or reuse them 925 * @param bool 926 */ 927 public void useExclusiveConditions(boolean bool) { 928 exclusiveConditionsAvailable = bool; 929 } 930 931// /** 932// * Add a self-table reference to this context 933// * @param referencekey 934// * @param referenceidkey 935// */ 936// public void addReference(String referencekey, String referenceidkey) { 937// String alias = this.getDbIdentity(); 938// references.add(new String[]{this.getDbIdentity(), referencekey, referenceidkey, alias}); 939// } 940 /** 941 * Add a foreign table reference to this context 942 * @param c 943 */ 944 public void addReference(Context c) { 945 if (!refs.contains(c)) { 946 String alias = c.getDbIdentity(); 947 refs.add(c); 948 references.add(new String[]{alias, "ids", alias + "ids", alias, this.getDbIdentity()}); 949 } 950 } 951 List<Context> refs = new ArrayList<Context>(); 952 953 /** 954 * Add a foreign table reference to this context<br/><br/> 955 * Context c= Context.getFilesToContacts();<br/> 956 * c.addReference(Context.getFiles().getDbIdentity(), "cname", "filename");<br/> 957 * @param referencetable The table which will be joined 958 * @param referencekey The key column of the joined table 959 * @param referenceidkey They key column in the original table 960 */ 961 public void addReference(String referencetable, String referencekey, String referenceidkey) { 962 synchronized (this) { 963 String alias = referencetable; 964 references.add(new String[]{referencetable, referencekey, referenceidkey, alias, getDbIdentity()}); 965 } 966 } 967 968 /** 969 * @return the dbIdentity 970 */ 971 public String getDbIdentity() { 972 return dbIdentity; 973 } 974 975 public String getSearchFields() { 976 return defResultFields; 977 } 978// 979// public String[] getSearchHeaders() { 980// return searchHeaders; 981// } 982// 983// public DatabaseObject getParent() { 984// return parent; 985// } 986 987 /** 988 * @param dbIdentity the dbIdentity to set 989 */ 990 public final void setDbIdentity(String dbIdentity) { 991 this.dbIdentity = dbIdentity; 992 } 993 994 /** 995 * @return the subID 996 */ 997 public String getSubID() { 998 return subID; 999 } 1000 1001 /** 1002 * @return the IDENTITY CLASS 1003 */ 1004 public Class getIdentityClass() { 1005 return identityClass; 1006 } 1007 1008 /** 1009 * @param subID the subID to set 1010 */ 1011 public final void setSubID(String subID) { 1012 this.subID = subID; 1013 } 1014 1015 public String getReferences() { 1016 String cond = ""; 1017 if (references.size() > 0) { 1018 for (int i = 0; i < references.size(); i++) { 1019 if (references.get(i).length == 4) { 1020 cond += " LEFT OUTER JOIN " + references.get(i)[0] + " ON " + references.get(i)[3] + "." + references.get(i)[1] + " = " + references.get(i)[3] + "." + references.get(i)[2]; 1021 } else if (references.get(i).length == 5) { 1022 cond += " LEFT OUTER JOIN " + references.get(i)[0] + " ON " + references.get(i)[3] + "." + references.get(i)[1] + " = " + references.get(i)[4] + "." + references.get(i)[2]; 1023 } 1024 } 1025 } 1026 return cond; 1027 } 1028 1029 /** 1030 * @return the Company 1031 */ 1032 public boolean isCompany() { 1033 return isCompany; 1034 } 1035 1036 /** 1037 * @param Company the Company to set 1038 */ 1039 private void setCompany(boolean Company) { 1040 this.isCompany = Company; 1041 } 1042 1043 /** 1044 * @return the Customer 1045 */ 1046 private boolean isCustomer() { 1047 return isCustomer; 1048 } 1049 1050 /** 1051 * @param Customer the Customer to set 1052 */ 1053 private void setCustomer(boolean Customer) { 1054 this.isCustomer = Customer; 1055 } 1056 1057 /** 1058 * @return the Manufacturer 1059 */ 1060 private boolean isManufacturer() { 1061 return isManufacturer; 1062 } 1063 1064 private void setId(int id) { 1065 this.id = id; 1066 } 1067 1068 /** 1069 * @param Manufacturer the Manufacturer to set 1070 */ 1071 private void setManufacturer(boolean Manufacturer) { 1072 this.isManufacturer = Manufacturer; 1073 } 1074 1075 /** 1076 * @return the Supplier 1077 */ 1078 private boolean isSupplier() { 1079 return isSupplier; 1080 } 1081 1082 /** 1083 * @param Supplier the Supplier to set 1084 */ 1085 private void setSupplier(boolean Supplier) { 1086 this.isSupplier = Supplier; 1087 } 1088 1089 /** 1090 * @return the itemStatus 1091 */ 1092 public int getItemStatus() { 1093 return itemStatus; 1094 } 1095 1096 /** 1097 * @param itemStatus the itemStatus to set 1098 */ 1099 public void setItemStatus(int itemStatus) { 1100 this.itemStatus = itemStatus; 1101 } 1102 1103 /** 1104 * @return the itemType 1105 */ 1106 public int getItemType() { 1107 return itemType; 1108 } 1109 1110 /** 1111 * @param itemType the itemType to set 1112 */ 1113 public void setItemType(int itemType) { 1114 this.itemType = itemType; 1115 } 1116 1117 /** 1118 * Returns an empty "sample" Object of the context type 1119 * @param <T> 1120 * @return An empty {@link DatabaseObject} 1121 */ 1122 @SuppressWarnings("unchecked") 1123 public <T extends DatabaseObject> T getSampleObject() { 1124 return (T) DatabaseObject.getObject(this); 1125 } 1126//////////////////////////////////////////////////////////////////////////////// 1127//generate a new Context Object on each call here, callers may alter them to variants 1128 1129 public static synchronized Context getContactsCompanies() { 1130 Context c = new Context(); 1131 c.setCompany(true); 1132 c.setSubID(DEFAULT_SUBID); 1133 c.setDbIdentity(IDENTITY_CONTACTS); 1134 c.setSearchFields(DEFAULT_CONTACT_SEARCH); 1135// c.setSearchHeaders(Headers.CONTACT_DEFAULT.getValue()); 1136 c.setIdentityClass(IDENTITY_CONTACTS_CLASS); 1137 c.setId(0); 1138 1139 return c; 1140 } 1141 1142 /** 1143 * 1144 * @param type 1145 * @param status 1146 * @return 1147 */ 1148 public static synchronized Context getItem(Integer type, Integer status) { 1149 Context c = new Context(); 1150 c.setSubID(DEFAULT_SUBID); 1151 c.setDbIdentity(IDENTITY_ITEMS); 1152 c.setSearchFields(DEFAULT_ITEM_SEARCH); 1153// c.setSearchHeaders(Headers.ITEM_DEFAULT.getValue()); 1154 c.setIdentityClass(IDENTITY_ITEMS_CLASS); 1155 if (status != null) { 1156 c.setItemStatus(status); 1157 } 1158 if (type != null) { 1159 c.setItemType(type); 1160 } 1161 c.setId(1); 1162 1163 return c; 1164 } 1165 1166 public static synchronized Context getItem() { 1167 return getItem(null, null); 1168 } 1169 1170 public static synchronized Context getSubItem() { 1171 Context subitem = new Context(); 1172 subitem.setSubID(DEFAULT_SUBID); 1173 subitem.setDbIdentity(IDENTITY_SUBITEMS); 1174 subitem.setIdentityClass(IDENTITY_SUBITEMS_CLASS); 1175 subitem.setId(2); 1176 1177 return subitem; 1178 } 1179 1180 public static synchronized Context getCustomer() { 1181 Context c = new Context(); 1182 c.setCustomer(true); 1183 c.setSubID(DEFAULT_SUBID); 1184 c.setDbIdentity(IDENTITY_CONTACTS); 1185 c.setSearchFields(DEFAULT_CONTACT_SEARCH); 1186// c.setSearchHeaders(Headers.CONTACT_DEFAULT.getValue()); 1187 c.setIdentityClass(IDENTITY_CONTACTS_CLASS); 1188 c.setId(3); 1189 1190 return c; 1191 } 1192 1193 public static synchronized Context getManufacturer() { 1194 Context c = new Context(); 1195 c.setManufacturer(true); 1196 c.setSubID(DEFAULT_SUBID); 1197 c.setDbIdentity(IDENTITY_CONTACTS); 1198 c.setSearchFields(DEFAULT_CONTACT_SEARCH); 1199// c.setSearchHeaders(Headers.CONTACT_DEFAULT.getValue()); 1200 c.setIdentityClass(IDENTITY_CONTACTS_CLASS); 1201 c.setId(4); 1202 1203 return c; 1204 } 1205 1206 public static synchronized Context getSupplier() { 1207 Context c = new Context(); 1208 c.setSupplier(true); 1209 c.setSubID(DEFAULT_SUBID); 1210 c.setDbIdentity(IDENTITY_CONTACTS); 1211 c.setSearchFields(DEFAULT_CONTACT_SEARCH); 1212// c.setSearchHeaders(Headers.CONTACT_DEFAULT.getValue()); 1213 c.setIdentityClass(IDENTITY_CONTACTS_CLASS); 1214 c.setId(5); 1215 1216 return c; 1217 } 1218 1219 public static synchronized Context getContact() { 1220 Context c = new Context(); 1221 c.setSubID(DEFAULT_SUBID); 1222 c.setDbIdentity(IDENTITY_CONTACTS); 1223 c.setSearchFields(DEFAULT_CONTACT_SEARCH); 1224// c.setSearchHeaders(Headers.CONTACT_DEFAULT.getValue()); 1225 c.setIdentityClass(IDENTITY_CONTACTS_CLASS); 1226 c.setId(6); 1227 1228 return c; 1229 } 1230 1231 public static synchronized Context getUser() { 1232 Context c = new Context(); 1233 c.setSubID(DEFAULT_SUBID); 1234 c.setDbIdentity(IDENTITY_USERS); 1235 c.setSearchFields(DEFAULT_USER_SEARCH); 1236// c.setSearchHeaders(Headers.USER_DEFAULT.getValue()); 1237 c.setIdentityClass(IDENTITY_USERS_CLASS); 1238 c.uniqueColumns = UNIQUE…
Large files files are truncated, but you can click here to view the full file