PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/db/common/Context.java

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