Skip to content

Commit 941d3a3

Browse files
committed
Basic import and export examples
1 parent 10ecde0 commit 941d3a3

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<%@ page import="java.util.*,com.navnorth.learningregistry.*" %>
2+
3+
<%
4+
// Setup exporter
5+
int batchSize = 100;
6+
String url = "lrtest02.learningregistry.org";
7+
LRExporter exporterLR = new LRExporter(batchSize, url);
8+
9+
// Configure exporter
10+
try
11+
{
12+
exporterLR.configure();
13+
}
14+
catch (LRException e)
15+
{
16+
return;
17+
}
18+
19+
// Setup signer
20+
String publicKeyLocation = "publicly accessible url of public key";
21+
String privateKey = "location on disk of private key";
22+
String passPhrase = "pass phrase";
23+
LRSigner signerLR = new LRSigner(publicKeyLocation, privateKey, passPhrase);
24+
25+
// Setup envelope parameters
26+
// These values will usually remain the same for all envelopes of the same schema and type
27+
String[] payloadSchema = new String[1];
28+
payloadSchema[0] = "NSDL DC 1.02.020";
29+
String resourceDataType = "metadata";
30+
String payloadSchemaURL = "url of schema description";
31+
String payloadPlacement = "inline";
32+
33+
// Setup data parameters
34+
// These values depend on the data being drawn on
35+
String rData = "resource data";
36+
String rUrl = "url of resource";
37+
String curator = "Curator";
38+
String provider = "Provider";
39+
String keys[] = new String[2];
40+
keys[0] = "example key one";
41+
keys[1] = "example key two";
42+
String submitter = "Submitter";
43+
String submitterType = "agent";
44+
String submissionTOS = "Submitter TOS";
45+
String submissionAttribution = "Submitter Attribution";
46+
String signer = "Signer";
47+
48+
// Build resource envelope
49+
// In a production environment, you would likely put many envelopes into the exporter before sending the data
50+
LREnvelope doc = new LRSimpleDocument(rData, resourceDataType, rUrl, curator, provider, keys, payloadPlacement, payloadSchemaURL, payloadSchema, submitter, submitterType, submissionTOS, submissionAttribution, signer);
51+
52+
// Add envelope to exporter
53+
exporterLR.addDocument(doc);
54+
55+
// Send data and get responses
56+
List<LRResponse> responses;
57+
try
58+
{
59+
responses = exporterLR.sendData();
60+
}
61+
catch(LRException e)
62+
{
63+
return;
64+
}
65+
66+
// Parse responses
67+
out.print("<h1>Export Results</h1>");
68+
for (LRResponse res : responses)
69+
{
70+
out.print("<h2>Batch Results</h2>");
71+
out.print("Status Code: " + res.getStatusCode());
72+
out.print("<br/>");
73+
out.print("Status Reason: " + res.getStatusReason());
74+
out.print("<br/>");
75+
out.print("Batch Success: " + res.getBatchSuccess());
76+
out.print("<br/>");
77+
out.print("Batch Response: " + res.getBatchResponse());
78+
out.print("<br/>");
79+
out.print("<br/>");
80+
out.print("<h3>Exported Resources</h3>");
81+
82+
for(String id : res.getResourceSuccess())
83+
{
84+
out.print("Id: " + id);
85+
out.print("<br/>");
86+
}
87+
88+
out.print("<br/>");
89+
out.print("<h3>Export Errors</h3>");
90+
91+
for(String message : res.getResourceFailure())
92+
{
93+
out.print("Error: " + message);
94+
out.print("<br/>");
95+
}
96+
}
97+
%>

examples/import_data.jsp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<%@ page import="org.json.*,java.util.*,com.navnorth.learningregistry.*" %>
2+
3+
<%
4+
5+
// Setup importer
6+
String node = "lrtest02.learningregistry.org";
7+
LRImporter importerLR = new LRImporter(node, true);
8+
9+
// Make harvest query based on a given resource url
10+
String id = "http://www.google.com";
11+
LRResult result = importerLR.getHarvestJSONData(id, true, false);
12+
13+
// Get data from result
14+
// This is raw JSON data from the Learning Registry node
15+
JSONObject json = result.getData();
16+
17+
try
18+
{
19+
out.print(json.toString());
20+
}
21+
catch(Exception e)
22+
{
23+
return;
24+
}
25+
26+
%>

0 commit comments

Comments
 (0)