{"id":235,"date":"2013-07-13T17:38:25","date_gmt":"2013-07-13T17:38:25","guid":{"rendered":"http:\/\/www.corrspt.com\/blog\/?p=235"},"modified":"2013-07-13T17:44:10","modified_gmt":"2013-07-13T17:44:10","slug":"introducing-xalpi-alternative-api-for-xeo-applications","status":"publish","type":"post","link":"http:\/\/www.corrspt.com\/blog\/2013\/07\/13\/introducing-xalpi-alternative-api-for-xeo-applications\/","title":{"rendered":"Introducing XALPI &#8211; Alternative API for XEO Applications"},"content":{"rendered":"<h1>XALPI<\/h1>\n<p>Hi everyone,<\/p>\n<p>I&#8217;ve been working on an application, using the <a title=\"XEO Framework\" href=\"http:\/\/www.xeoframework.org\/\" target=\"_blank\">XEO Framework<\/a>, for a while now and there were two situations that I wanted to improve. First it was my inability to write unit tests for my application&#8217;s logic (using <a title=\"jUnit\" href=\"http:\/\/junit.org\/\" target=\"_blank\">JUnit<\/a>, for example) and the other was I had trouble finding which attributes were being used where and overall can&#8217;t rely on the compiler to help me out. XEO&#8217;s API is very flexible and all but I thought that in order to address these two issues I would have to come up with something on my own.<\/p>\n<p>Notice: This work is not associated with the XEO Framework, although I do work at ITDS (which creates the framework), XALPI does not reflect anything but my own opinion and effort on the subject.<\/p>\n<p>Meet <a title=\"XALPI\" href=\"https:\/\/bitbucket.org\/corrspt\/xalpi\/wiki\/Home\" target=\"_blank\">XALPI<\/a>! (beta)<\/p>\n<p>XALPI stands for <strong>X<\/strong>EO <strong>AL<\/strong>ternative A<strong>PI<\/strong> and is a <strong><em>personal<\/em><\/strong> attempt to create a more convenient (for me) API and allow the creation of unit tests. It&#8217;s an open source project that you can find on <a title=\"XALPI\" href=\"https:\/\/bitbucket.org\/corrspt\/xalpi\/wiki\/edit\/Home\">Bitbucket<\/a>, licensed under the <a title=\"BSD License Revision 3\" href=\"http:\/\/en.wikipedia.org\/wiki\/BSD_licenses#3-clause_license_.28.22Revised_BSD_License.22.2C_.22New_BSD_License.22.2C_or_.22Modified_BSD_License.22.29\">BSD license<\/a>\u00a0(rev3), meaning you can do just about anything with it.<\/p>\n<p>You can download it <a title=\"XALPI Binary\" href=\"https:\/\/bitbucket.org\/corrspt\/xalpi\/downloads\/XALPI.zip\">here<\/a> (see the instructions at the wiki page).<\/p>\n<p>So, what makes <a title=\"XALPI\" href=\"https:\/\/bitbucket.org\/corrspt\/xalpi\/wiki\/edit\/Home\">XALPI<\/a> different from XEO&#8217;s original API?<\/p>\n<ul>\n<li>Provides an interface representing each XEOModel with getters and setters for each attribute (see example bellow)<\/li>\n<li>Set iFile values using java.io.File instances<\/li>\n<li>Get\/Set Lov Values using a class instance (good for searching references) instead of the value itself<\/li>\n<li>The description of each attribute\/model is placed as <em>javadoc<\/em> in the generated interfaces \/ classes<\/li>\n<li>Provides an easy API to create lists of objects and iterate a list<\/li>\n<li>Provides a new Logger abstraction to allow creating application logic to be tested without needing the XEO Logger (which throws a bunch of errors to the error console when the server is not up and running)<\/li>\n<li>Reduces the number of <em>boRuntimeExceptions<\/em> thrown by the API (only update\/destroy throw exceptions)<\/li>\n<\/ul>\n<p>Each of these situations is (I hope) well explained at the wiki. Although some information may still be missing ( it&#8217;s beta after all ) I will, to the best of my abilities, complete it as fast as I can.<\/p>\n<p>An example? Compare the following code (current API) :<\/p>\n<pre class=\"brush:java\">public void createHistory(EboContext ctx, BigDecimal patientBoui) throws boRuntimeException {\r\n\t\tTimestamp time = DateUtils.getTodayDateAsTimeStamp();\r\n\t\tlong boui = patientBoui.longValue();\r\n        boObjectListBuilder builder = new boObjectListBuilder(ctx, \"select FileHistory where user = CTX_PERFORMER_BOUI and file = ? and dateOpen = ?\").argsList(boui,time).cache(false);\r\n\t\tboObjectList list = builder.build();\r\n\t\tif (list.getRecordCount() == 0){\r\n\r\n\t\t\tif (logger.isFineEnabled()){\r\n\t\t\t\tlogger.fine(\"Created fileHistory for \" + patientBoui.longValue());\r\n\t\t\t}\r\n\r\n\t\t\tboObject historyEntry = boApplication.getDefaultApplication().getObjectManager().createObject(ctx, FileHistory.MODEL_NAME);\r\n\t\t\thistoryEntry.getAttribute(FileHistory.USER).setValueLong(ctx.getBoSession().getPerformerBoui());\r\n\t\t\thistoryEntry.getAttribute(FileHistory.FILE).setValueLong(boui);\r\n\t\t\thistoryEntry.getAttribute(FileHistory.DATE_OPEN).setValueDate(DateUtils.getTodayDate());\r\n\t\t\thistoryEntry.update();\r\n\t    } \r\n\t}<\/pre>\n<p>With this (XALPI) :<\/p>\n<pre class=\"brush:java\">public void createHistory(Patient fileOpened, BaseModel user) throws boRuntimeException{\r\n\r\n\t\tTimestamp time = DateUtils.getTodayDateAsTimeStamp();\r\n\t\tFileHistoryList history = Select.FileHistory().where(\"user = CTX_PERFORMER_BOUI and file = ? and dateOpen = ?\").args(fileOpened,time).build();\r\n\r\n\t\tif (history.isEmpty()){\r\n\r\n\t\t\tlogger.fine(\"Created fileHitroy for %s\",user.getBoui());\r\n\r\n\t\t\tFileHistory history = FileHistoryManager.create();\r\n\r\n\t\t\thistory.setDateOpen(DateUtils.getTodayDate());\r\n\t\t\thistory.setFile(fileOpened);\r\n\t\t\thistory.setUser(user);\r\n\t\t\thistory.update();\r\n\t\t}\r\n\r\n\t}<\/pre>\n<p>Check <a title=\"XALPI wiki\" href=\"https:\/\/bitbucket.org\/corrspt\/xalpi\/wiki\/Home\">out the rest at the wiki page<\/a> and tell me if you like it. I&#8217;m open to suggestions and improvements<\/p>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>XALPI Hi everyone, I&#8217;ve been working on an application, using the XEO Framework, for a while now and there were two situations that I wanted to improve. First it was my inability to write unit tests for my application&#8217;s logic &hellip; <a href=\"http:\/\/www.corrspt.com\/blog\/2013\/07\/13\/introducing-xalpi-alternative-api-for-xeo-applications\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[24,45,26,25,23,44],"class_list":["post-235","post","type-post","status-publish","format-standard","hentry","category-java","category-xeo","tag-api","tag-java","tag-junit","tag-unit-testing","tag-xalpi","tag-xeo"],"_links":{"self":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/comments?post=235"}],"version-history":[{"count":13,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/235\/revisions"}],"predecessor-version":[{"id":260,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/235\/revisions\/260"}],"wp:attachment":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/media?parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/categories?post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/tags?post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}