PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/db/objects/Schedule.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 401 lines | 246 code | 39 blank | 116 comment | 23 complexity | 435a1b19318adc5236ac37a0fad7d9d5 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. /*
  2. * This file is part of YaBS.
  3. *
  4. * YaBS is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * YaBS is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with YaBS. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package mpv5.db.objects;
  18. import java.util.ArrayList;
  19. import java.util.Calendar;
  20. import java.util.Date;
  21. import javax.swing.JComponent;
  22. import mpv5.db.common.Context;
  23. import mpv5.db.common.DatabaseObject;
  24. import mpv5.db.common.NodataFoundException;
  25. import mpv5.db.common.QueryCriteria;
  26. import mpv5.db.common.QueryHandler;
  27. import mpv5.db.objects.Item;
  28. import mpv5.logging.Log;
  29. import mpv5.usermanagement.MPSecurityManager;
  30. import mpv5.utils.date.DateConverter;
  31. import mpv5.utils.date.vTimeframe;
  32. import mpv5.utils.images.MPIcon;
  33. /**
  34. *
  35. *
  36. */
  37. public class Schedule extends DatabaseObject {
  38. private static final long serialVersionUID = 1L;
  39. private int usersids = 4343;
  40. private int itemsids;
  41. private int contactsids;
  42. private Date nextdate = new Date();
  43. private Date stopdate = new Date();
  44. private Date startdate = new Date();
  45. private int intervalmonth = 1;
  46. private int eventtype = 0;
  47. private Item item;
  48. private boolean isdone;
  49. private Contact contact;
  50. public Schedule() {
  51. setContext(Context.getSchedule());
  52. }
  53. /**
  54. *
  55. * @return A vTimeframe object with this schedules day set
  56. */
  57. public vTimeframe getDate() {
  58. Calendar c = Calendar.getInstance();
  59. c.setTime(__getNextdate());
  60. c.add(Calendar.DAY_OF_MONTH, 1);
  61. vTimeframe t = new vTimeframe(__getNextdate(), new Date(c.getTimeInMillis() - 1));
  62. return t;
  63. }
  64. /**
  65. *
  66. * @return The item assigned to this schedule object
  67. * @throws mpv5.db.common.NodataFoundException
  68. */
  69. public Item getItem() throws NodataFoundException {
  70. if (item == null && __getItemsids() >= 0) {
  71. item = (Item) DatabaseObject.getObject(Context.getItem(), __getItemsids());
  72. }
  73. return item;
  74. }
  75. /**
  76. *
  77. * @return The item assigned to this schedule object
  78. * @throws mpv5.db.common.NodataFoundException
  79. */
  80. public Contact getContact() throws NodataFoundException {
  81. if (contact == null && __getContactsids() >= 0 ) {
  82. contact = (Contact) DatabaseObject.getObject(Context.getContact(), __getContactsids());
  83. }
  84. return contact;
  85. }
  86. /**
  87. *
  88. * @param date
  89. * @return
  90. */
  91. public static ArrayList<Schedule> getEvents(vTimeframe date) {
  92. Object[][] data = QueryHandler.instanceOf().clone(Context.getSchedule()).select("ids", null, "nextdate", date);
  93. ArrayList<Schedule> l = new ArrayList<Schedule>();
  94. for (int i = 0; i < data.length; i++) {
  95. Object[] objects = data[i];
  96. try {
  97. Schedule s = (Schedule) DatabaseObject.getObject(Context.getSchedule(), Integer.valueOf(objects[0].toString()));
  98. l.add(s);
  99. } catch (NodataFoundException ex) {
  100. Log.Debug(ex);
  101. }
  102. }
  103. return l;
  104. }
  105. /**
  106. *
  107. * @param date
  108. * @return
  109. */
  110. public static ArrayList<Schedule> getEvents2(vTimeframe date) {
  111. ArrayList<Schedule> l = new ArrayList<Schedule>();
  112. QueryCriteria criteria = new QueryCriteria("intervalmonth", 0);
  113. try {
  114. Object[][] data = QueryHandler.instanceOf().clone(Context.getSchedule()).select("IDS", criteria, date, "nextdate");
  115. for (int i = 0; i < data.length; i++) {
  116. Object[] objects = data[i];
  117. Schedule s = (Schedule) DatabaseObject.getObject(Context.getSchedule(), Integer.valueOf(objects[0].toString()));
  118. l.add(s);
  119. }
  120. return l;
  121. } catch (NodataFoundException ex) {
  122. Log.Debug(Schedule.class, ex.getMessage());
  123. return l;
  124. }
  125. }
  126. /**
  127. *
  128. * @param dataOwner
  129. * @return
  130. */
  131. public static ArrayList<Schedule> getEvents(Contact dataOwner) {
  132. ArrayList<Schedule> l = new ArrayList<Schedule>();
  133. if (dataOwner != null) {
  134. String query =
  135. "SELECT ids FROM " + Context.getSchedule().getDbIdentity() +
  136. " WHERE itemsids IN (SELECT ids FROM " +
  137. Context.getItem().getDbIdentity() +
  138. " WHERE contactsids = " + dataOwner.__getIDS() + ")";
  139. Object[][] data = QueryHandler.instanceOf().clone(Context.getSchedule()).freeSelectQuery(query, MPSecurityManager.VIEW, null).getData();
  140. for (int i = 0; i < data.length; i++) {
  141. Object[] objects = data[i];
  142. try {
  143. Schedule s = (Schedule) DatabaseObject.getObject(Context.getSchedule(), Integer.valueOf(objects[0].toString()));
  144. l.add(s);
  145. } catch (NodataFoundException ex) {
  146. Log.Debug(ex);
  147. }
  148. }
  149. }
  150. return l;
  151. }
  152. /**
  153. *
  154. * @param dataOwner
  155. * @return
  156. */
  157. public static ArrayList<Schedule> getEvents2(Contact dataOwner) {
  158. ArrayList<Schedule> l = new ArrayList<Schedule>();
  159. Object[][] data;
  160. if (dataOwner != null) {
  161. QueryCriteria criteria = new QueryCriteria("contactsids", dataOwner.__getIDS());
  162. try {
  163. data = QueryHandler.instanceOf().clone(Context.getSchedule()).select("IDS", criteria);
  164. for (int i = 0; i < data.length; i++) {
  165. Object[] objects = data[i];
  166. try {
  167. Schedule s = (Schedule) DatabaseObject.getObject(Context.getSchedule(), Integer.valueOf(objects[0].toString()));
  168. l.add(s);
  169. } catch (NodataFoundException ex) {
  170. Log.Debug(ex);
  171. }
  172. }
  173. } catch (NodataFoundException ex) {
  174. Log.Debug(Schedule.class, ex.getMessage());
  175. }
  176. }
  177. return l;
  178. }
  179. /**
  180. *
  181. * @param dataOwner
  182. * @return
  183. */
  184. public static ArrayList<Schedule> getEvents(Item dataOwner) {
  185. ArrayList<Schedule> l = new ArrayList<Schedule>();
  186. if (dataOwner != null) {
  187. String query =
  188. "SELECT ids FROM " + Context.getSchedule().getDbIdentity() +
  189. " WHERE itemsids = " + dataOwner.__getIDS();
  190. Object[][] data = QueryHandler.instanceOf().clone(Context.getSchedule()).freeSelectQuery(query, MPSecurityManager.VIEW, null).getData();
  191. for (int i = 0; i < data.length; i++) {
  192. Object[] objects = data[i];
  193. try {
  194. Schedule s = (Schedule) DatabaseObject.getObject(Context.getSchedule(), Integer.valueOf(objects[0].toString()));
  195. l.add(s);
  196. } catch (NodataFoundException ex) {
  197. Log.Debug(ex);
  198. }
  199. }
  200. }
  201. return l;
  202. }
  203. /**
  204. *
  205. * @param dataOwner
  206. * @return
  207. */
  208. public static ArrayList<Schedule> getEvents2(Item dataOwner) {
  209. ArrayList<Schedule> l = new ArrayList<Schedule>();
  210. Object[][] data;
  211. if (dataOwner != null) {
  212. QueryCriteria criteria = new QueryCriteria("itemsids", dataOwner.__getIDS());
  213. try {
  214. data = QueryHandler.instanceOf().clone(Context.getSchedule()).select("IDS", criteria);
  215. for (int i = 0; i < data.length; i++) {
  216. Object[] objects = data[i];
  217. try {
  218. Schedule s = (Schedule) DatabaseObject.getObject(Context.getSchedule(), Integer.valueOf(objects[0].toString()));
  219. if (s.__getIntervalmonth() >= 1) {
  220. l.add(s);
  221. }
  222. } catch (NodataFoundException ex) {
  223. Log.Debug(ex);
  224. }
  225. }
  226. } catch (NodataFoundException ex) {
  227. Log.Debug(Schedule.class, ex.getMessage());
  228. }
  229. }
  230. return l;
  231. }
  232. /**
  233. *
  234. * @param day
  235. * @return
  236. */
  237. public static ArrayList<Schedule> getEvents(Date day) {
  238. return getEvents(new vTimeframe(day, new Date(DateConverter.addDay(day).getTime() - 1)));
  239. }
  240. public static ArrayList<Schedule> getEvents2(Date day) {
  241. return getEvents2(new vTimeframe(day, new Date(DateConverter.addDay(day).getTime() - 1)));
  242. }
  243. @Override
  244. public JComponent getView() {
  245. throw new UnsupportedOperationException("Not supported yet.");
  246. }
  247. /**
  248. * @return the usersids
  249. */
  250. public int __getUsersids() {
  251. return usersids;
  252. }
  253. /**
  254. * @param usersids the usersids to set
  255. */
  256. public void setUsersids(int usersids) {
  257. this.usersids = usersids;
  258. }
  259. /**
  260. * @return the itemsids
  261. */
  262. public int __getItemsids() {
  263. return itemsids;
  264. }
  265. /**
  266. * @param itemsids the itemsids to set
  267. */
  268. public void setItemsids(int itemsids) {
  269. this.itemsids = itemsids;
  270. }
  271. public int __getContactsids() {
  272. return contactsids;
  273. }
  274. public void setContactsids(int contactsids) {
  275. this.contactsids = contactsids;
  276. }
  277. public int __getEventtype() {
  278. return eventtype;
  279. }
  280. public void setEventtype(int eventtype) {
  281. this.eventtype = eventtype;
  282. }
  283. /**
  284. * @return the nextdate
  285. */
  286. public Date __getNextdate() {
  287. return nextdate;
  288. }
  289. /**
  290. * @param nextdate the nextdate to set
  291. */
  292. public void setNextdate(Date nextdate) {
  293. this.nextdate = nextdate;
  294. }
  295. /**
  296. * @return the intervalmonth
  297. */
  298. public int __getIntervalmonth() {
  299. return intervalmonth;
  300. }
  301. /**
  302. * @param intervalmonth the intervalmonth to set
  303. */
  304. public void setIntervalmonth(int intervalmonth) {
  305. this.intervalmonth = intervalmonth;
  306. }
  307. @Override
  308. public mpv5.utils.images.MPIcon getIcon() {
  309. if (!__getIsdone()) {
  310. return new MPIcon("/mpv5/resources/images/32/knewstuff.png");
  311. } else {
  312. return new MPIcon("/mpv5/resources/images/32/clean.png");
  313. }
  314. }
  315. /**
  316. * Array representation of this event.
  317. * <br/>{getItem(), intervalmonth, stopdate, user}
  318. * @return
  319. */
  320. @Override
  321. public Object[] toArray() {
  322. Object[] t = new Object[]{this, intervalmonth, DateConverter.getDefDateString(stopdate),
  323. User.getUsername(usersids)};
  324. return t;
  325. }
  326. /**
  327. * @return the stopdate
  328. */
  329. public Date __getStopdate() {
  330. return stopdate;
  331. }
  332. /**
  333. * @param stopdate the stopdate to set
  334. */
  335. public void setStopdate(Date stopdate) {
  336. this.stopdate = stopdate;
  337. }
  338. /**
  339. * @return the startdate
  340. */
  341. public Date __getStartdate() {
  342. return startdate;
  343. }
  344. /**
  345. * @param startdate the startdate to set
  346. */
  347. public void setStartdate(Date startdate) {
  348. this.startdate = startdate;
  349. }
  350. /**
  351. * @return the isdone
  352. */
  353. public boolean __getIsdone() {
  354. return isdone;
  355. }
  356. /**
  357. * @param isdone the isdone to set
  358. */
  359. public void setIsdone(boolean isdone) {
  360. this.isdone = isdone;
  361. }
  362. }