Skip to content

Commit 1bb5055

Browse files
authored
Merge pull request #6 from Distributed-Noracle/develop
Develop
2 parents 1a9ef37 + da99b87 commit 1bb5055

18 files changed

+280
-132
lines changed

.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
66
<classpathentry kind="lib" path="lib/junit-4.12.jar"/>
77
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
8-
<classpathentry kind="lib" path="lib/las2peer-bundle-0.7-SNAPSHOT.jar"/>
8+
<classpathentry kind="lib" path="lib/las2peer-bundle-0.7.1.jar"/>
99
<classpathentry kind="lib" path="lib/jersey-media-json-jackson-2.25.1.jar"/>
1010
<classpathentry kind="output" path="output"/>
1111
</classpath>

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ ivy.jar
1919
!/etc/ivy/ivysettings.xml
2020
*.secret
2121
archiva_credentials.xml
22+
join-example-space.html
23+
/frontend/

agent-developer.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<las2peer:agent type="user">
2+
<id>f3ef36da93ea0875f840797d34cab1b2063df63107bb206238b46e92420f446453c6bb980b234a60986b3facd663cd6e416bcc49c60adca187922926c2bdf047</id>
3+
<publickey encoding="base64">rO0ABXNyABRqYXZhLnNlY3VyaXR5LktleVJlcL35T7OImqVDAgAETAAJYWxnb3JpdGhtdAASTGphdmEvbGFuZy9TdHJpbmc7WwAHZW5jb2RlZHQAAltCTAAGZm9ybWF0cQB+AAFMAAR0eXBldAAbTGphdmEvc2VjdXJpdHkvS2V5UmVwJFR5cGU7eHB0AANSU0F1cgACW0Ks8xf4BghU4AIAAHhwAAABJjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIAPE7NS9qdSf9RgZnPd2jCKemrXYNozq1VeQBOdzOOJucRKtnAOKrj+/h7IzYolZvcsra9D/NDewJu4T/luPMPSjnREBp0t/J5arUKyqcg5xbpR7bHEj+PccvlMxXncEuSBGl9eis7+5//eEH66MTDNj3wtdIqFMvSLHYDGZpfKLZ3P40AfRnAJjO8guGZDmBVa5PohdCToWm/isH+/lmqZb0/t2hmVBgG4AR4dN0FeslRfprVfK4b76HFOzxTq8rC41cB35JKVd23R8GL2fpdZBgWdvOFg/5rMxXu8RBHmSibyLf/0XIdEj8nYxHMqqJXDTmQFbmShhHUy7pO5OtkCAwEAAXQABVguNTA5fnIAGWphdmEuc2VjdXJpdHkuS2V5UmVwJFR5cGUAAAAAAAAAABIAAHhyAA5qYXZhLmxhbmcuRW51bQAAAAAAAAAAEgAAeHB0AAZQVUJMSUM=</publickey>
4+
<privatekey encrypted="AES" keygen="PBKDF2WithHmacSHA1">
5+
<salt encoding="base64">OuTHTH6uApSIdPvLyTGsMQ==</salt>
6+
<data encoding="base64">woXeiqUeFhrXyYvFYd+QMlK1rnI5mHIVmRFgshbQO4Sic6byDe/JF2LXpnRnP10G9tJAdQ7/yKzS7siostU08wGOCluACSJQC4Nt9zBDH9+fA8MTDyiaTVXjh78oW3wA0t9KLiY6iuYK9dZt2yMSdSa2eUO7ZtjolP10It9vemtInNTRXDxo1LmBHPoFm7eN0hHgasUflPQs9XfJ0JERGv/5+CfxuXiP3wg9SV7SnfkJUJCfxS8fmLadjGwthuexuNzUJqj/VYdBw2d3XKPQ53cFiC9j7miQOs+u8mlvX87FGO8tFlPwYzY+kfA1qOrdkszddzaCA4AQtD1jL5QzGixVR5C1EQ4I7k5LujHfYmSG2cja5p/Zm49ouTVmwe2mQI8mSoM91d/+RmQP1lYs5lND+dLegOiEfr71rssNHfoXHbqxlt6KT0E7l8ghUSgO6FrltH5J/DiETnSnpkfZ2I94lbEc6XMFojbyzqe7HucR9n926bOUcxwErFro+7NJLMtLMaBSdL5ECaPZjJ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1X+/9sF/Lr0lEefd4ST/YHA5DfZyZYwJNcphHcdmqF8mXwhxJ4JlaXIBw76/kMZLOH98npyTDmI6Dx+igRnbXXgd41BuW7RHgbRLIpC6gBuCnOUYuIqz6PAY7JpR1F7W5e3c3NIIUmm83mUmBaHBx9K/0DGau6oCj2zFOi94oAXkNjI9vUkiHIJVIkMxFfOmERtKHjqwGp17t50wXdgdAmMpekadj1yWX20zTHUf9US1r8yge12Dd3RDL9bjgUSY/BySMrnlgTCLKkJ4S6QZixYWUPryCUy8exHUxPIMbKIqZHKvRStUoFgn52B8y8+Pq3K1NCjlRj+pv+Xdo5E000a3stHGc7k8Svp4jdtrVFsSGRNDkUkKGIjW96CgwZZE7dprRoi</data>
7+
</privatekey>
8+
<login>developer</login>
9+
</las2peer:agent>

build.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<project name="Distributed-Noracle-Service" default="jar" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">
22

3-
<property name="core.version" value="0.7-SNAPSHOT" />
3+
<property name="core.version" value="0.7.1" />
44

55
<property name="service.name" value="i5.las2peer.services.noracleService" />
66
<property name="service.class" value="NoracleService" />
@@ -63,6 +63,7 @@
6363
<credentials host="role.dbis.rwth-aachen.de:9911/archiva" realm="Repository internal" />
6464
</ivy:settings>
6565
<ivy:retrieve type="jar, bundle" conf="*" pattern="${lib}/[artifact]-[revision].[ext]" />
66+
<get src="https://github.com/rwth-acis/las2peer-FileService/releases/download/2.2.0/i5.las2peer.services.fileService-2.2.0.jar" dest="service/"/>
6667
</target>
6768

6869

launcher-configuration.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ service
99

1010
[commands]
1111
uploadStartupDirectory('example')
12+
uploadServicePackage('service/i5.las2peer.services.fileService-2.2.0.jar', 'agent-developer.xml', 'topsecret')
13+
startService('i5.las2peer.services.fileService.FileService@2.2.0','testtest')
14+
uploadServicePackage('service/i5.las2peer.services.noracleService-0.5.0.jar', 'agent-developer.xml', 'topsecret')
1215
startService('i5.las2peer.services.noracleService.NoracleSpaceService@0.5.0','testtest')
1316
startService('i5.las2peer.services.noracleService.NoracleQuestionService@0.5.0','testtest')
1417
startService('i5.las2peer.services.noracleService.NoracleQuestionRelationService@0.5.0','testtest')
1518
startService('i5.las2peer.services.noracleService.NoracleAgentService@0.5.0','testtest')
19+
startService('i5.las2peer.services.noracleService.NoracleVoteService@0.5.0','testtest')
1620
startService('i5.las2peer.services.noracleService.NoracleService@0.5.0','testtest')
1721
startWebConnector
1822
interactive

noracle-generate-examples.sh

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ space_creator_agent_login="noracle-example-smith"
88
agent_pw="testtest"
99

1010
num_spaces=5
11-
num_questions_per_space=50
12-
num_relations_per_space=25
11+
num_questions_per_space=25
12+
num_relations_per_space=15
1313

1414
relation_types=()
1515
relation_types+=("\"name\": \"Similarity\", \"directed\": \"false\"")
@@ -27,18 +27,24 @@ random_lengthLorem() {
2727

2828
# create example spaces
2929

30-
for num in {1..${num_spaces}}; do
31-
curl -s -D - --user noracle-example-smith:${agent_pw} -X POST --header 'Content-Type: application/json' -d '{ "name": "example-space-'"${num}"'" }' "${endpoint}"'/spaces' --insecure
30+
for (( num=1; num<=${num_spaces}; num++ )); do
31+
curl -s -D - --user noracle-example-smith:${agent_pw} -X POST --header 'Content-Type: application/json' -d '{ "name": "example-space-'"${num}"'" }' "${endpoint}"'/spaces' --insecure &
3232
done
33+
# wait till all requests terminated
34+
wait
3335

3436

3537
# get all subscribed spaces for agent smith
38+
example_space_ids=()
39+
out="$( { curl -s --user noracle-example-smith:${agent_pw} -X GET --header 'Accept: application/json' "${endpoint}"'/agents/'"${space_creator_agent_id}"'/spacesubscriptions' --insecure ; } 2>&1 )"
40+
while read spaceId ; do
41+
example_space_ids+=("${spaceId}")
42+
done < <(echo "${out}" | jq -r '.[].spaceId')
3643

37-
out="$( { curl -s --user noracle-example-smith:${agent_pw} -X GET --header 'Accept: application/json' "${endpoint}"'/agents/'"${space_creator_agent_id}"'/spacesubscriptions' --insecure ; } )"
38-
echo "${out}" | jq -r '.[].spaceId' | while read spaceId ; do
44+
for spaceId in "${example_space_ids[@]}" ; do
3945
# create questions inside space
4046
question_ids=()
41-
for num in {1..${num_questions_per_space}}; do
47+
for (( num=1; num<=${num_questions_per_space}; num++ )); do
4248
random=$(random_lengthLorem)
4349
out="$( { curl -s -D - --user noracle-example-smith:"${agent_pw}" -X POST --header 'Content-Type: application/json' -d '{ "text": "'"${random}"'" }' "${endpoint}"'/spaces/'"${spaceId}"'/questions' --insecure ; } 2>&1 )"
4450
echo "${out}"
@@ -54,7 +60,7 @@ echo "${out}" | jq -r '.[].spaceId' | while read spaceId ; do
5460
question_ids+=(${question_id})
5561
done
5662
# create random relations between questions
57-
for num in {1..${num_relations_per_space}}; do
63+
for (( num=1; num<=${num_relations_per_space}; num++ )); do
5864
relation_type=${relation_types[$RANDOM % ${#relation_types[@]} ]}
5965
first_question_id=${question_ids[$RANDOM % ${#question_ids[@]} ]}
6066
second_question_id=${question_ids[$RANDOM % ${#question_ids[@]} ]}
@@ -63,3 +69,28 @@ echo "${out}" | jq -r '.[].spaceId' | while read spaceId ; do
6369
done
6470
done
6571

72+
# generate join links
73+
space_join_links=""
74+
for spaceId in "${example_space_ids[@]}" ; do
75+
out="$( { curl -s -D - --user noracle-example-smith:${agent_pw} -X GET --header 'Accept: application/json' "${endpoint}"'/spaces/'"${spaceId}" --insecure ; } 2>&1 )"
76+
while read spaceSecret ; do
77+
space_join_links="${space_join_links}<div><a href=\"http://dbis.rwth-aachen.de/noracle/spaces/${spaceId}?pw=${spaceSecret}\">Click here to join example space ${spaceId}</a></div>"
78+
done < <(echo "${out}" | jq -r '.spaceSecret')
79+
done
80+
81+
# write invitation links to file
82+
read -d '' join_space_file_content <<- EOF
83+
<html>
84+
<head>
85+
<title>Join A Noracle Example Space</title>
86+
</head>
87+
<body>
88+
<p>Please click on a link below to join the appropriate Noracle example space</p>
89+
${space_join_links}
90+
</body>
91+
</html>
92+
93+
EOF
94+
95+
echo "${join_space_file_content}" > "join-example-space.html"
96+

src/main/i5/las2peer/services/noracleService/NoracleAgentService.java

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
/**
2525
* Noracle Agents Service
2626
*
27-
* This service is used to handle agents metadata in a distributed Noracle system.
27+
* This service is used to handle agents metadata in a distributed Noracle
28+
* system.
2829
*
2930
*/
3031
public class NoracleAgentService extends Service implements INoracleAgentService {
@@ -124,10 +125,6 @@ public SpaceSubscriptionList getSpaceSubscriptions(String agentId) throws Servic
124125
}
125126
}
126127

127-
private String buildSubscriptionId(String agentId) {
128-
return "spacesubscriptions-" + agentId;
129-
}
130-
131128
@Override
132129
public SpaceSubscription updateSpaceSubscription(String agentId, String spaceId, String[] selectedQuestions)
133130
throws ServiceInvocationException {
@@ -162,8 +159,58 @@ public SpaceSubscription updateSpaceSubscription(String agentId, String spaceId,
162159

163160
@Override
164161
public NoracleAgentProfile updateAgentProfile(String agentName) throws ServiceInvocationException {
165-
// TODO Implement (create or update should both be done here)
166-
return null;
162+
Agent mainAgent = Context.get().getMainAgent();
163+
String envIdentifier = buildAgentProfileId(mainAgent.getIdentifier());
164+
Envelope env;
165+
NoracleAgentProfile profile;
166+
// look for existing profile, otherwise create one
167+
try {
168+
try {
169+
env = Context.get().requestEnvelope(envIdentifier);
170+
profile = (NoracleAgentProfile) env.getContent();
171+
} catch (EnvelopeNotFoundException e) {
172+
env = Context.get().createEnvelope(envIdentifier);
173+
profile = new NoracleAgentProfile();
174+
}
175+
} catch (EnvelopeAccessDeniedException e) {
176+
throw new ServiceAccessDeniedException("Envelope access denied");
177+
} catch (EnvelopeOperationFailedException e) {
178+
throw new InternalServiceException("Could not create new envelope for noracle agent profile", e);
179+
}
180+
profile.setName(agentName);
181+
env.setContent(profile);
182+
env.setPublic();
183+
try {
184+
Context.get().storeEnvelope(env, mainAgent);
185+
} catch (EnvelopeAccessDeniedException e) {
186+
throw new ServiceAccessDeniedException("Envelope access denied");
187+
} catch (EnvelopeOperationFailedException e) {
188+
throw new InternalServiceException("Storing envelope with noracle agent profile failed", e);
189+
}
190+
return profile;
191+
}
192+
193+
@Override
194+
public NoracleAgentProfile getAgentProfile(String agentId) throws ServiceInvocationException {
195+
String envIdentifier = buildAgentProfileId(agentId);
196+
try {
197+
Envelope env = Context.get().requestEnvelope(envIdentifier);
198+
return (NoracleAgentProfile) env.getContent();
199+
} catch (EnvelopeAccessDeniedException e) {
200+
throw new ServiceAccessDeniedException("Envelope access denied");
201+
} catch (EnvelopeOperationFailedException e) {
202+
throw new InternalServiceException("Could not fetch agent profile", e);
203+
} catch (EnvelopeNotFoundException e) {
204+
return new NoracleAgentProfile();
205+
}
206+
}
207+
208+
private String buildSubscriptionId(String agentId) {
209+
return "spacesubscriptions-" + agentId;
210+
}
211+
212+
private String buildAgentProfileId(String agentId) {
213+
return "noracleagentprofile-" + agentId;
167214
}
168215

169216
}

src/main/i5/las2peer/services/noracleService/NoracleService.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@
1414
import io.swagger.annotations.SwaggerDefinition;
1515

1616
@Api
17-
@SwaggerDefinition(
18-
info = @Info(
19-
title = "Noracle Service",
20-
version = NoracleService.API_VERSION,
21-
description = "A bundle service for the distributed Noracle system",
22-
license = @License(
23-
name = "BSD-3",
24-
url = "https://github.com/rwth-acis/Noracle-Bundle-Service/blob/master/LICENSE")))
17+
@SwaggerDefinition(info = @Info(title = "Noracle Service", version = NoracleService.API_VERSION, description = "A bundle service for the distributed Noracle system", license = @License(name = "BSD-3", url = "https://github.com/Distributed-Noracle/Distributed-Noracle-Backend/blob/master/LICENSE.txt")))
2518
@ServicePath("/" + NoracleService.RESOURCE_NAME)
2619
public class NoracleService extends RESTService {
2720

src/main/i5/las2peer/services/noracleService/NoracleVoteService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class NoracleVoteService extends Service implements INoracleVoteService {
2222
private static final int MAX_VOTES_PER_OBJECT = 1000000;
2323

2424
@Override
25-
public void setVote(String agentId, String objectId, int vote) throws ServiceInvocationException {
25+
public Vote setVote(String agentId, String objectId, int vote) throws ServiceInvocationException {
2626
Agent mainAgent = Context.get().getMainAgent();
2727
if (objectId == null || objectId.isEmpty()) {
2828
throw new InvocationBadArgumentException("No object id given");
@@ -41,6 +41,7 @@ public void setVote(String agentId, String objectId, int vote) throws ServiceInv
4141
voteEntry.setVote(pubVote);
4242
persEnv.setContent(voteEntry);
4343
Context.get().storeEnvelope(persEnv);
44+
return pubVote;
4445
} catch (EnvelopeNotFoundException e) {
4546
Envelope persEnv = Context.get().createEnvelope(persEnvId);
4647
String pubEnvId = null;
@@ -66,6 +67,7 @@ public void setVote(String agentId, String objectId, int vote) throws ServiceInv
6667
VoteEntry voteEntry = new VoteEntry(objectId, pubIndex, pubVote);
6768
persEnv.setContent(voteEntry);
6869
Context.get().storeEnvelope(persEnv);
70+
return pubVote;
6971
}
7072
} catch (EnvelopeAccessDeniedException e) {
7173
throw new ServiceAccessDeniedException("Envelope Access Denied");

src/main/i5/las2peer/services/noracleService/api/INoracleAgentService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public interface INoracleAgentService {
99

1010
public NoracleAgentProfile updateAgentProfile(String agentName) throws ServiceInvocationException;
1111

12+
public NoracleAgentProfile getAgentProfile(String agentId) throws ServiceInvocationException;
13+
1214
public SpaceSubscription subscribeToSpace(String spaceId, String spaceSecret) throws ServiceInvocationException;
1315

1416
public void unsubscribeFromSpace(String spaceId) throws ServiceInvocationException;

0 commit comments

Comments
 (0)