PageRenderTime 36ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/server/XMLRPCHandler.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 93 lines | 79 code | 10 blank | 4 comment | 6 complexity | d7663b9997e3d71dbe68576fabfeaf80 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.server;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import mpv5.db.common.Context;
  6. import mpv5.db.common.DatabaseObject;
  7. import mpv5.db.common.NodataFoundException;
  8. import mpv5.logging.Log;
  9. import mpv5.usermanagement.MPSecurityManager;
  10. /**
  11. *
  12. * @author andreasw
  13. */
  14. public class XMLRPCHandler {
  15. public String[] getAvailableContexts() {
  16. ArrayList<Context> c = Context.getImportableContexts();
  17. String[] s = new String[c.size()];
  18. for (int i = 0; i < c.size(); i++) {
  19. s[i] = c.get(i).getDbIdentity();
  20. }
  21. return s;
  22. }
  23. public boolean login(String user, String passw) throws Exception {
  24. Log.Debug(this, "Login " + user);
  25. return MPSecurityManager.checkAuth(user, passw) != null;
  26. }
  27. public HashMap<String, Object> getObjects(String context, int startid, int endid) throws Exception {
  28. Log.Debug(this, "Getting " + context + " ids: " + startid + " to " + endid);
  29. HashMap<String, Object> m = new HashMap<String, Object>();
  30. for (int i = startid; i <= endid; i++) {
  31. try {
  32. DatabaseObject d = DatabaseObject.getObject(Context.getMatchingContext(context), i);
  33. HashMap<String, Object> m2 = new HashMap<String, Object>();
  34. List<Object[]> l = d.getValues2();
  35. for (Object[] objects : l) {
  36. m2.put(objects[0].toString(), objects[1]);
  37. }
  38. m.put(context + " [" + i + "]", m2);
  39. } catch (NodataFoundException nodataFoundException) {
  40. Log.Debug(this, nodataFoundException);
  41. }
  42. }
  43. return m;
  44. }
  45. public HashMap<String, Object> getObject(String context, int id) throws Exception {
  46. Log.Debug(this, "Getting " + context + " id: " + id);
  47. DatabaseObject d = DatabaseObject.getObject(Context.getMatchingContext(context), id);
  48. HashMap<String, Object> m = new HashMap<String, Object>();
  49. List<Object[]> l = d.getValues2();
  50. for (Object[] objects : l) {
  51. m.put(objects[0].toString(), objects[1]);
  52. }
  53. return m;
  54. }
  55. public HashMap<String, Object> getObject(String context, String cname) throws Exception {
  56. Log.Debug(this, "Getting " + context + " cname: " + cname);
  57. DatabaseObject d = DatabaseObject.getObject(Context.getMatchingContext(context), cname);
  58. HashMap<String, Object> m = new HashMap<String, Object>();
  59. List<Object[]> l = d.getValues2();
  60. for (Object[] objects : l) {
  61. m.put(objects[0].toString(), objects[1]);
  62. }
  63. return m;
  64. }
  65. public boolean addObject(String context, HashMap<String, Object> data) throws Exception {
  66. Log.Debug(this, "Adding " + context + " data: " + data);
  67. DatabaseObject d = DatabaseObject.getObject(Context.getMatchingContext(context));
  68. d.parse(data);
  69. d.setIDS(-1);
  70. return d.saveImport();
  71. }
  72. public boolean updateObject(String context, int id, HashMap<String, Object> data) throws Exception {
  73. Log.Debug(this, "Updating " + context + " id: " + id + " data: " + data);
  74. DatabaseObject d = DatabaseObject.getObject(Context.getMatchingContext(context), id);
  75. d.parse(data);
  76. d.setIDS(id);
  77. return d.save();
  78. }
  79. public boolean deleteObject(String context, int id) throws Exception {
  80. Log.Debug(this, "Deleting " + context + " id: " + id);
  81. return DatabaseObject.getObject(Context.getMatchingContext(context), id).delete();
  82. }
  83. }