Code Monkey home page Code Monkey logo

javarosa's Introduction

ODK JavaRosa

Platform License Build status Slack

JavaRosa is a Java library for rendering forms that are compliant with ODK XForms spec. It is at the heart of many of the ODK tools. ODK JavaRosa is a fork of JavaRosa 1.0 that has been modified to NOT run on J2ME devices. The key differences are:

  • Regularly updated to ensure spec compliance
  • KoBo additional instance defn. and filter paths
  • remember all bind attributes and any additional attributes on <input>, <select>, <group>, etc. statements
  • numerous enhancements and contributions from SurveyCTO and others.
  • J2ME sub-projects removed

ODK JavaRosa is part of ODK, a free and open-source set of tools which help organizations author, field, and manage mobile data collection solutions. Learn more about the ODK project and its history here and read about example ODK deployments here.

Releases

Releases are available from Maven Central.

Snapshots versions are also published for each commit to master and are available from oss.sonatype.org.

Requirements

JavaRosa works on Android API level 21+ (with desugaring enabled) and Java 8+.

Extending

JavaRosa is intended be extended to support extra features through a "plugin" approach documented here .

Development

Setting up your development environment

  1. Fork the javarosa project (why and how to fork)

  2. Clone your fork of the project locally. At the command line:

     git clone https://github.com/YOUR-GITHUB-USERNAME/javarosa
    

We recommend using IntelliJ IDEA for development. On the welcome screen, click Import Project, navigate to your javarosa folder, and select the build.gradle file. Use the defaults through the wizard. Once the project is imported, IntelliJ may ask you to update your remote Maven repositories. Follow the instructions to do so.

Building the project

To build the project, go to the View menu, then Tool Windows > Gradle. build will be in javarosa > Tasks > build > build. Double-click build to package the application. This Gradle task will now be the default action in your Run menu.

To package a jar, use the jar Gradle task.

Running benchmarks

JavaRosa can be used to parse and fill very large forms on inexpensive devices and so it's important to keep an eye on performance. Benchmarks using JMH and the JMH Gradle plugin have been introduced to compare relative performance as code changes are made. We have found that running these benchmarks with the jmh Gradle task or through IntelliJ can produce inconsistent results. The most reliable way we have found to run them is to first build a jar with the jmhJar Gradle task and then to run the jar:

    java -jar build/libs/javarosa-jmh.jar ChildVaccination

This also makes it easy to selectively run a subset of benchmarks by including a regular expression as an argument. In the example above, only benchmarks that include the text "ChildVaccination" will be executed. Run java -jar build/libs/javarosa-jmh.jar -h to see other JMH configuration options.

While benchmarks can help identify relative performance improvements or regressions, they are not always a reliable proxy for how code will perform in a realistic context. Profiling is helpful for identifying parts of the code that are worth analyzing and optimizing as well as to validate that any performance changes have the intended effects.

Contributing code

Any and all contributions to the project are welcome. ODK JavaRosa is used across the world primarily by organizations with a social purpose so you can have real impact!

If you're ready to contribute code, see the contribution guide.

Downloading builds

Per-commit debug builds can be found on CircleCI. Login with your GitHub account, click the build you'd like, then find the JAR in the Artifacts tab under $CIRCLE_ARTIFACTS.

Publishing the jar to OSSRH and Maven Central

Project maintainers have the private keys to upload signed jars to Sonatype's OSS Repository Hosting (OSSRH) service which is then synced to Maven's Central Repository. This process is outlined here.

While Gradle is the default build tool for all ODK tools (including this one), Maven is used for for publishing the jar because OSSRH's Gradle support is unreliable (e.g., snapshots don't always update). This means version and dependency changes must be made in both build.gradle and pom.xml.

Deviations from OSSRH's documentation are that maintainers use gpg2 v2.1 and greater (not gpg), the latest versions of the Maven plugins in pom.xml, and a secrets.xml file that include the GPG home directory, key name, and pass phrase. All that is needed in the GPG home directory is private-keys-v1.d and pubring.gpg.

<!-- secrets.xml -->
<settings>
    <servers>
        <server>
            <id>ossrh</id>
            <username>getodk</username>
            <password>very-secure-password</password>
        </server>
    </servers>
    <profiles>
        <profile>
            <id>ossrh</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <gpg.executable>/path/to/gpg2</gpg.executable>
                <gpg.homedir>/path/to/javarosa/gpg/folder</gpg.homedir>
                <gpg.keyname>1234ABCD</gpg.keyname>
                <gpg.passphrase>very-secure-passphrase</gpg.passphrase>
            </properties>
        </profile>
    </profiles>
</settings>

Official releases are built by a Github action when a commit is tagged. Before tagging a release:

  1. Update the version in build.gradle and pom.xml and merge the changes to master.
    • Use x.x.x-SNAPSHOT for snapshots releases and x.x.x for production releases.

To manually generate official signed releases, you'll need the GPG folder, GPG passwords, a configured secrets.xml file.

  1. Run mvn -v to confirm the Java version and vendor used to build the release.
  2. In the repo folder, run mvn -s secrets.xml clean deploy to publish.
    • If successful, both snapshots and production releases will appear in OSSRH here.
    • Production releases are automatically synced to Central here a few hours later.

Don't forget to update the build.gradle files in any downstream tools (e.g., ODK Collect, ODK Briefcase) to the newest version!

javarosa's People

Contributors

abbyad avatar adewinter avatar alxndrsn avatar bderenzi avatar chartung avatar cooperka avatar ctsims avatar dcbriccetti avatar dmyung avatar dsrees avatar ggalmazor avatar gmimano avatar grzesiek2010 avatar hallahan avatar jd-alexander avatar johnthebeloved avatar lognaturel avatar macdude357 avatar meletis avatar mitchellsundt avatar mloudon avatar mrgriscom avatar munafsheikh avatar neal0892 avatar rowenaluk avatar seadowg avatar snopoke avatar sophroneo avatar tiritea avatar yanokwa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

javarosa's Issues

trigger control does not save any data in the instance

Originally reported by: Yaw Anokwa (Bitbucket: yanokwa, GitHub: yanokwa)


for the trigger control it seems like jr j2meapp doesn't save anything in the instance.

that is, if i select "ok" after a trigger and i come back to that question, it doesn't remember that i clicked ok. might be good to have that data in the instance

also, if you mark a trigger as required, you can't go past it.


bind datatype 'long' can't be deserialized

Originally reported by: Anonymous


After storing an unsent form that holds a input field of datatype 'long', i.e.

the form can't be opened again, neither can the 'saved forms' list, due to exception:

//unhandled exception in gui-cl => java.lang.RuntimeException[Error deserializing bytestream for type [fg]; No datatype registration to serialization code [c9 55 48 ff]]//

orignally posted at
https://groups.google.com/forum/#!topic/javarosa-developers/21iPw3gXmV8


fail gracefully when encountering an unknown function

Originally reported by: Yaw Anokwa (Bitbucket: yanokwa, GitHub: yanokwa)


When loading a form with arbitrary function calls, javarosa dies with an unhandled exception.
example where review() is the arbitrary function:

E/AndroidRuntime( 743): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 743): org.javarosa.xpath.XPathUnhandledException: XPath evaluation: cannot handle function 'review'
E/AndroidRuntime( 743): at org.javarosa.xpath.expr.XPathFuncExpr.eval(XPathFuncExpr.java:155)
E/AndroidRuntime( 743): at org.javarosa.xpath.XPathConditional.evalRaw(XPathConditional.java:57)
E/AndroidRuntime( 743): at org.javarosa.xpath.XPathConditional.eval(XPathConditional.java:61)
E/AndroidRuntime( 743): at org.javarosa.core.model.FormDef.evaluateConstraint(FormDef.java:520)

This should be handled gracefully and either logged as a warning/error, or pushed through the UI to the user. Either way, the form should still work.


core crashes on select with no items

Originally reported by: Yaw Anokwa (Bitbucket: yanokwa, GitHub: yanokwa)


attached form crashes jr core with nullpointer exception at

java.lang.NullPointerException
       at org.javarosa.core.model.QuestionDef.localizeSelectMap(QuestionDef.java:259)
       at org.javarosa.xform.parse.XFormParser.parseControl(XFormParser.java:468)
       at org.javarosa.xform.parse.XFormParser$6.handle(XFormParser.java:120)
       at org.javarosa.xform.parse.XFormParser.parseElement(XFormParser.java:287)
       at org.javarosa.xform.parse.XFormParser.parseElement(XFormParser.java:296)
       at org.javarosa.xform.parse.XFormParser.parseElement(XFormParser.java:296)
       at org.javarosa.xform.parse.XFormParser.getFormDef(XFormParser.java:264)
       at org.javarosa.xform.parse.XFormParser.getFormDef(XFormParser.java:225)
       at org.javarosa.xform.util.XFormUtils.getFormFromInputStream(XFormUtils.java:50)

the problem is that one of the selects has a label but no items

<select1 ref="in14">
	<label ref="jr:itext('in14')"/>
</select1>

the core should throw a more useful error.


need ability to load xforms via usb

Originally reported by: apoku (Bitbucket: apoku, GitHub: apoku)


Specifically when dynamically loading any number of forms, it is difficult to have the full JR experience on phones without GPRS service. As of now, once JR has been installed on the phone, the only dynamic option for loading new forms can occur by downloading forms over GPRS.

Proposal is for:

  • A way one can load xforms into the application without
    pulling them down from a remote server.
  • A way for Xforms to be transferred via USB
  • Users should be able to load as many xform(s) as desired after JR has been installed (i.e. Xforms need not be bundled with local build).

See discussion on javaRosa-implementers google group:
http://groups.google.com/group/javarosa-implementers/browse_thread/thread/6d4883d226f645eb


relevancy bug in nested groups with relevancy conditions based off calculated nodes

Originally reported by: Drew Roos (Bitbucket: mrgriscom, GitHub: mrgriscom)


i've discovered what i believe to be a bug in the propogation of chained conditions/relevancy. take the following form:

==========

#!xml

<h:html xmlns:h="http://www.w3.org/1999/xhtml"
        xmlns="http://www.w3.org/2002/xforms"
        xmlns:ev="http://www.w3.org/2001/xml-events"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:jr="http://openrosa.org/javarosa">
<h:head>
  <h:title>group relevancy bug</h:title>
    <model>
      <instance>
        <form xmlns="">

<outer_trigger />
<inner_trigger />

<outer>
  <inner>
    <target_question />
  </inner>
  <inner_condition />
</outer>

<end />

        </form>
      </instance>
    
<bind nodeset="inner_trigger" type="int" />
<bind nodeset="outer/inner_condition" calculate="/form/inner_trigger &lt; 10" />
<bind nodeset="outer" relevant="../outer_trigger and ../outer_trigger != 'A'" />
<bind nodeset="outer/inner" relevant="../inner_condition" />
        
    </model>
</h:head>            
<h:body>

<input ref="inner_trigger"><label>inner trigger (enter 5)</label></input>
<input ref="outer_trigger"><label>outer trigger (enter 'D')</label></input>
<input ref="outer/inner/target_question"><label>target question: i am incorrectly skipped</label></input>
<input ref="end"><label>this is the end of the form</label></input>
   
</h:body>
</h:html>

==========

answer 5 for the first question, and 'D' for the second question. the 'target question' will be skipped, but i believe it should show up, since all the relevancy conditions for its containing groups ('inner' and 'outer') are satisfied.

the problem case above is pretty specific; namely, changing any of the following will cause target_question to show correctly:

  • the relevancy of 'inner' must refer to a calculated node; putting the condition from inner_condition directly in the 'relevant' for 'inner' causes no bug
  • the calculated node 'inner_condition' must be inside 'outer'. putting it at the top level does not trigger the bug
  • inner_trigger must be asked before outer_trigger. switching the order causes no bug
  • the relevancy of outer must start out false by default. changing the relevancy to just '../outer_trigger != 'A'' doesn't trigger the bug, as outer_trigger begins null, and null != 'A', thus making the 'outer' group relevant
  • making inner_condition trivially dependent on outer_trigger doesn't cause the bug. i.e.,

i suspect that the problem comes from inner_condition initially being non-relevant by virtue of the containing group 'outer' being non-relevant. when 'outer' becomes relevant, the relevancy for its child nodes is not re-computed or was not pre-computed properly.


[itext:n] appearing in restored instances

Originally reported by: Yaw Anokwa (Bitbucket: yanokwa, GitHub: yanokwa)


if you fill out a form with itext data for answers and restore it from xml, the answers displayed are "[itext:0]".

we discovered and fixed this in odk (see http://code.google.com/p/open-data-kit/issues/detail?id=45), but it should be fixed in the core.

<> suggests this fix in XFormAnswerDataParser.java:getSelection()

if (q != null) {
    if (q.getSelectItems() == null) {
        q.localizeSelectMap(null);
    }
    int index = q.getSelectedItemIndex(choice);
    s.attachQuestionDef(q);
    return (index != -1 ? s : null);
}
return true;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.