Skip to content

Commit 21c7cbc

Browse files
committed
Merge pull request #27 from brianjmiller/master
Rewrite of LRS interface and RemoteLRS
2 parents 6324bbc + 8d88a86 commit 21c7cbc

30 files changed

+1586
-421
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: java
2+
jdk: openjdk7
3+
before_script: cp src/test/resources/travis-ci.properties src/test/resources/lrs.properties

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
A Java library for implementing with the Tin Can API.
22

3+
[![Build Status](https://travis-ci.org/RusticiSoftware/TinCanJava.png)](https://travis-ci.org/RusticiSoftware/TinCanJava)
4+
35
For hosted API documentation, basic usage instructions, supported version listing, etc. visit the main project website at:
46

57
http://rusticisoftware.github.io/TinCanJava/

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</configuration>
5252
<version>3.0</version>
5353
</plugin>
54-
<plugin>
54+
<!--<plugin>
5555
<groupId>org.projectlombok</groupId>
5656
<artifactId>lombok-maven-plugin</artifactId>
5757
<version>0.11.6.0</version>
@@ -67,7 +67,7 @@
6767
<addOutputDirectory>false</addOutputDirectory>
6868
<sourceDirectory>src/main/java</sourceDirectory>
6969
</configuration>
70-
</plugin>
70+
</plugin>-->
7171
<plugin>
7272
<groupId>org.apache.maven.plugins</groupId>
7373
<artifactId>maven-surefire-plugin</artifactId>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
Copyright 2014 Rustici Software
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package com.rusticisoftware.tincan;
17+
18+
import com.fasterxml.jackson.databind.JsonNode;
19+
import com.fasterxml.jackson.databind.node.ArrayNode;
20+
import com.fasterxml.jackson.databind.node.ObjectNode;
21+
import com.rusticisoftware.tincan.json.JSONBase;
22+
import com.rusticisoftware.tincan.json.Mapper;
23+
import com.rusticisoftware.tincan.json.StringOfJSON;
24+
import lombok.Data;
25+
import lombok.EqualsAndHashCode;
26+
27+
import java.io.IOException;
28+
import java.net.URISyntaxException;
29+
import java.util.ArrayList;
30+
import java.util.Iterator;
31+
import java.util.List;
32+
33+
@Data
34+
@EqualsAndHashCode(callSuper = false)
35+
public class About extends JSONBase{
36+
private List<TCAPIVersion> version;
37+
private Extensions extensions;
38+
39+
public About(String str) throws IOException, URISyntaxException {
40+
StringOfJSON jsonStr = new StringOfJSON(str);
41+
init(jsonStr.toJSONNode());
42+
}
43+
44+
public About(StringOfJSON jsonStr) throws IOException, URISyntaxException{
45+
init(jsonStr.toJSONNode());
46+
}
47+
48+
public About(JsonNode jsonNode) throws URISyntaxException{
49+
init(jsonNode);
50+
}
51+
52+
private void init(JsonNode jsonNode) throws URISyntaxException{
53+
54+
if(jsonNode.hasNonNull("version")) {
55+
56+
Iterator it = jsonNode.get("version").elements();
57+
58+
while(it.hasNext()){
59+
if(version == null) { version = new ArrayList<TCAPIVersion>(); }
60+
version.add(TCAPIVersion.fromString(((JsonNode)it.next()).textValue()));
61+
}
62+
}
63+
64+
if(jsonNode.hasNonNull("extensions")) {
65+
extensions = new Extensions(jsonNode.get("extensions"));
66+
}
67+
}
68+
69+
@Override
70+
public ObjectNode toJSONNode(TCAPIVersion v) {
71+
ObjectNode result = new ObjectNode(Mapper.getInstance().getNodeFactory());
72+
if(!version.isEmpty()){
73+
ArrayNode versions = Mapper.getInstance().createArrayNode();
74+
for(TCAPIVersion tcapiVersion: this.getVersion()){
75+
versions.add(tcapiVersion.toString());
76+
}
77+
result.put("version", versions);
78+
}
79+
80+
if(extensions != null){
81+
result.put("extensions", extensions.toJSONNode());
82+
}
83+
84+
return result;
85+
}
86+
87+
}

src/main/java/com/rusticisoftware/tincan/ContextActivities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
160160
}
161161
}
162162
if (this.category != null && this.category.size() > 0) {
163-
if (version.ordinal() >= TCAPIVersion.V100.ordinal()) {
163+
if (version.ordinal() <= TCAPIVersion.V100.ordinal()) {
164164
ArrayNode category = mapper.createArrayNode();
165165
node.put("category", category);
166166

src/main/java/com/rusticisoftware/tincan/LRS.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,38 @@
1515
*/
1616
package com.rusticisoftware.tincan;
1717

18+
import com.rusticisoftware.tincan.documents.*;
19+
import com.rusticisoftware.tincan.lrsresponses.*;
20+
1821
import java.util.List;
1922
import java.util.UUID;
2023

2124
/**
2225
* Define the interface that must be satisfied to talk to an LRS
2326
*/
2427
public interface LRS {
25-
Statement retrieveStatement(String id) throws Exception;
26-
Statement retrieveVoidedStatement(String id) throws Exception;
27-
StatementsResult queryStatements(StatementsQueryInterface query) throws Exception;
28-
StatementsResult moreStatements(String moreURL) throws Exception;
29-
UUID saveStatement(Statement statement) throws Exception;
30-
List<String> saveStatements(List<Statement> statements) throws Exception;
31-
32-
State retrieveState(String id, String activityId, Agent agent, UUID registration) throws Exception;
33-
void saveState(State state, String activityId, Agent agent, UUID registration) throws Exception;
34-
}
28+
AboutLRSResponse about() throws Exception;
29+
30+
StatementLRSResponse saveStatement(Statement statement) throws Exception;
31+
StatementsResultLRSResponse saveStatements(List<Statement> statements) throws Exception;
32+
StatementLRSResponse retrieveStatement(String id) throws Exception;
33+
StatementLRSResponse retrieveVoidedStatement(String id) throws Exception;
34+
StatementsResultLRSResponse queryStatements(StatementsQueryInterface query) throws Exception;
35+
StatementsResultLRSResponse moreStatements(String moreURL) throws Exception;
36+
37+
ProfileKeysLRSResponse retrieveStateIds(Activity activity, Agent agent, UUID registration) throws Exception;
38+
StateLRSResponse retrieveState(String id, Activity activity, Agent agent, UUID registration) throws Exception;
39+
LRSResponse saveState(StateDocument state) throws Exception;
40+
LRSResponse deleteState(StateDocument state) throws Exception;
41+
LRSResponse clearState(Activity activity, Agent agent, UUID registration) throws Exception;
42+
43+
ProfileKeysLRSResponse retrieveActivityProfileIds(Activity activity) throws Exception;
44+
ActivityProfileLRSResponse retrieveActivityProfile(String id, Activity activity) throws Exception;
45+
LRSResponse saveActivityProfile(ActivityProfileDocument profile) throws Exception;
46+
LRSResponse deleteActivityProfile(ActivityProfileDocument profile) throws Exception;
47+
48+
ProfileKeysLRSResponse retrieveAgentProfileIds(Agent agent) throws Exception;
49+
AgentProfileLRSResponse retrieveAgentProfile(String id, Agent agent) throws Exception;
50+
LRSResponse saveAgentProfile(AgentProfileDocument profile) throws Exception;
51+
LRSResponse deleteAgentProfile(AgentProfileDocument profile) throws Exception;
52+
}

0 commit comments

Comments
 (0)