Lets say you want to upload a file (e.g., test.png) to RAMADDA. First you need to establish a session with RAMADDA. You can just do a url get with:
https://<server>:<https port>/repository/user/login?output=xml&user.password=<password>&user.id=<user> Or if you don't have https: http://<server>/repository/user/login?output=xml&user.password=<password>&user.id=<user>The output=xml tells RAMADDA to return the result as xml.
The above request returns xml of the form:
<response code="ok"> sessionid </response>Or if there was an error:
<response code="error"> some error message </response>Subsequent posts to RAMADDA just require an extra argument:
sessionid=<sessionid>You can also use RepositoryClient code:
RepositoryClient client = new RepositoryClient(server, 80, "/repository", userId,password); String[] msg = { "" }; if (client.isValidSession(true, msg)) { System.err.println("Valid session"); } else { System.err.println("Invalid session:" + msg[0]); }Next, create an entry xml file that defines the entries you want to create.
Now, zip up this xml file along with the file you want to upload and then post the zipped file to:
http://<server>/repository/entry/xmlcreateInclude the arguments:
output=xml sessionid=<sessionid> file=thezipfileNote: an alternative way to specify the destination parent entry in the repository is to pass the entry id in as a URL argument:
group=some parent entry idIf you are not uploading files you can just post the xml file instead of the zip file. In that case instead of a file= attribute in the xml use url=, e.g.,:
<entries> <entry name="Some opendap url" type="file" id="0" url="the opendap url" parent="<some parent entry id>" </entries>Either way, you will get back the response xml with either code=ok and a list of the entry ids created:
<response code="ok"> <entry id="1219161636252_0.6145187911490728_17"/> </response>Or an error response:
<response code="error"> error message </response>Here is a longer version of an entries file:
<entries> <entry description="" east="-3.950" file="test.xidv" fromdate="2008-08-19 16:01:00 GMT" id="0" name="test.png" north="71.864" parent="<some parent entry id>" south="-7.926" todate="2008-08-19 16:01:00 GMT" type="file" west="-198.358"/> <entry east="-3.950" file="test.png" fromdate="2008-08-19 16:01:00 GMT" id="1" name="test.png - Product" north="71.864" parent="<some parent entry id>" south="-7.926" todate="2008-08-19 16:01:00 GMT" type="file" west="-198.358"/> <association from="0" name="generated product" to="1"/> </entries>With its response:
<response code="ok"> <entry id="1219161636252_0.5912686911125428_33"/> <entry id="1219161636252_0.34475975368841827_34"/> <association id="1219161636252_0.18087075533515407_35"/> </response>
So to add a "tag" metadata use the xml:<entry ...> ... <metadata type="some type" attr1="atribute 1 value" attr2="attribute 2 value" .../>
If you have values that don't work as XML attributes due to their content or their length you can include them as tags. The encoded="false" says this is unencoded text. The default is encoded=true which implies the text is base64 encoded (see below).<metadata inherited="false" type="enum_tag" attr1="TAG VALUE">
A simple way to see the metadata xml is to create a folder or other entry in RAMADDA. Add a number of properties to it then do File->Export. Uzip the .zip file and look at the entries.xml Note: the contents of the attr tags are CDATA blocks of base64 encoded text. Base64 encoding of the text is the default and is what is expected when RAMADDA ingests this XML unless you have encoded=false.<metadata inherited="true" type="some type"> <attr index="1" encoded="false"><![CDATA[value 1]]></attr> <attr index="2" encoded="false"><![CDATA[value 2]]></attr> ... </metadata>
<metadata inherited="true" type="some type"> <attr index="1"><![CDATA[TlNGLU9QUA==]]></attr> <attr index="2"><![CDATA[SW5jcmV=]]></attr> ... </metadata>