- String uuid = path.substring(1, path.length() - ".xml".length());
- Node target = file.getSession().getNodeByIdentifier(uuid);
- // FIXME hard code terms path in order to test ODK Collect bug
- if (target.isNodeType(NodeType.MIX_REFERENCEABLE)) {
- file.setProperty(Property.JCR_ID, target);
- if (file.hasProperty(Property.JCR_PATH))
- file.getProperty(Property.JCR_PATH).remove();
- } else {
- file.setProperty(Property.JCR_PATH, target.getPath());
- if (file.hasProperty(Property.JCR_ID))
- file.getProperty(Property.JCR_ID).remove();
+ uuid = path.substring(1, path.length() - ".xml".length());
+ mimeType = EntityMimeType.XML.getMimeType();
+ } else if ("file-csv".equals(type)) {
+ if (!path.endsWith(".csv"))
+ throw new IllegalArgumentException("File uri " + instanceUri + " must end with .csv");
+ // Work around bug in ODK Collect not supporting paths
+ // path = path.substring(0, path.length() - ".csv".length());
+ // Node target = file.getSession().getNode(path);
+ uuid = path.substring(1, path.length() - ".csv".length());
+ mimeType = EntityMimeType.CSV.getMimeType();
+ } else {
+ throw new IllegalArgumentException("Unsupported instance type " + type);
+ }
+ Node manifest = JcrUtils.getOrAdd(form, OrxManifestName.manifest.name(),
+ OrxManifestName.manifest.get());
+ Node file = JcrUtils.getOrAdd(manifest, instanceId);
+ file.addMixin(NodeType.MIX_MIMETYPE);
+ file.setProperty(Property.JCR_MIMETYPE, mimeType);
+ file.setProperty(Property.JCR_ENCODING, encoding);
+ Node target = file.getSession().getNodeByIdentifier(uuid);
+
+ if (target.isNodeType(NodeType.NT_QUERY)) {
+ Query query = target.getSession().getWorkspace().getQueryManager().getQuery(target);
+ query.setLimit(10);
+ QueryResult queryResult = query.execute();
+ RowIterator rit = queryResult.getRows();
+ while (rit.hasNext()) {
+ Row row = rit.nextRow();
+ for (Value value : row.getValues()) {
+ System.out.print(value.getString());
+ System.out.print(',');
+ }
+ System.out.print('\n');