Skip to content

Commit 1bedf29

Browse files
authored
Merge pull request #68 from reTHINK-project/develop
Develop to master
2 parents 692c101 + 2a8b95b commit 1bedf29

18 files changed

Lines changed: 986 additions & 615 deletions

2.log

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2019-01-29T10:07:29.802+0000 I CONTROL [initandlisten] MongoDB starting : pid=23704 port=47017 dbpath=rs2 64-bit host=cangalho
2+
2019-01-29T10:07:29.802+0000 I CONTROL [initandlisten] db version v3.6.3
3+
2019-01-29T10:07:29.802+0000 I CONTROL [initandlisten] git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
4+
2019-01-29T10:07:29.802+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.0g 2 Nov 2017
5+
2019-01-29T10:07:29.802+0000 I CONTROL [initandlisten] allocator: tcmalloc
6+
2019-01-29T10:07:29.802+0000 I CONTROL [initandlisten] modules: none
7+
2019-01-29T10:07:29.802+0000 I CONTROL [initandlisten] build environment:
8+
2019-01-29T10:07:29.802+0000 I CONTROL [initandlisten] distarch: x86_64
9+
2019-01-29T10:07:29.802+0000 I CONTROL [initandlisten] target_arch: x86_64
10+
2019-01-29T10:07:29.802+0000 I CONTROL [initandlisten] options: { net: { port: 47017 }, replication: { replSet: "testeMongo" }, storage: { dbPath: "rs2" }, systemLog: { destination: "file", path: "2.log" } }
11+
2019-01-29T10:07:29.803+0000 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory rs2 not found., terminating
12+
2019-01-29T10:07:29.803+0000 I CONTROL [initandlisten] now exiting
13+
2019-01-29T10:07:29.803+0000 I CONTROL [initandlisten] shutting down with code:100

Dockerfile

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,15 @@ FROM java:8
22

33
#Install maven
44
RUN apt-get update
5+
56
RUN apt-get install -y maven
67

7-
8-
# gpg keys listed at https://github.com/nodejs/node
9-
#RUN set -ex \
10-
# && for key in \
11-
# 4ED778F539E3634C779C87C6D7062848A1AB005C \
12-
# B9E2F5981AA6E0CD28160D9FF13993A75599653C \
13-
# 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
14-
# B9AE9905FFD7803F25714661B63B535A4C206CA9 \
15-
# 77984A986EBC2AA786BC0F66B01FBB92821C587A \
16-
# 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
17-
# FD3A5288F042B6850C66B31F09FE44734EB7990E \
18-
# 8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
19-
# C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
20-
# DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
21-
# A48C2BEE680E841632CD4E44F07496B3EB3C1762 \
22-
#
23-
# ; do \
24-
# gpg --keyserver pool.sks-keyservers.net --recv-keys "$key"; \
25-
# done
26-
#
27-
#RUN set -ex gpg --keyserver pool.sks-keyservers.net --recv-keys "4ED778F539E3634C779C87C6D7062848A1AB005C"
28-
#RUN set -ex gpg --keyserver pool.sks-keyservers.net --recv-keys "B9E2F5981AA6E0CD28160D9FF13993A75599653C"
29-
#RUN set -ex gpg --keyserver pool.sks-keyservers.net --recv-keys "94AE36675C464D64BAFA68DD7434390BDBE9B9C5"
30-
#RUN set -ex gpg --keyserver pool.sks-keyservers.net --recv-keys "B9AE9905FFD7803F25714661B63B535A4C206CA9"
31-
#RUN set -ex gpg --keyserver pool.sks-keyservers.net --recv-keys "77984A986EBC2AA786BC0F66B01FBB92821C587A"
32-
#RUN set -ex gpg --keyserver pool.sks-keyservers.net --recv-keys "71DCFD284A79C3B38668286BC97EC7A07EDE3FC1"
33-
#RUN set -ex gpg --keyserver pool.sks-keyservers.net --recv-keys "FD3A5288F042B6850C66B31F09FE44734EB7990E"
34-
#RUN set -ex gpg --keyserver pool.sks-keyservers.net --recv-keys "8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600"
35-
#RUN set -ex gpg --keyserver pool.sks-keyservers.net --recv-keys "C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8"
36-
#RUN set -ex gpg --keyserver pool.sks-keyservers.net --recv-keys "DD8F2338BAE7501E3DD5AC78C273792F7D83545D"
37-
#RUN set -ex gpg --keyserver pool.sks-keyservers.net --recv-keys "A48C2BEE680E841632CD4E44F07496B3EB3C1762"
38-
#
39-
40-
ENV GPG_KEYS 4ED778F539E3634C779C87C6D7062848A1AB005C B9E2F5981AA6E0CD28160D9FF13993A75599653C 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 B9AE9905FFD7803F25714661B63B535A4C206CA9 77984A986EBC2AA786BC0F66B01FBB92821C587A 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 FD3A5288F042B6850C66B31F09FE44734EB7990E 8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 DD8F2338BAE7501E3DD5AC78C273792F7D83545D A48C2BEE680E841632CD4E44F07496B3EB3C1762
41-
RUN set -ex; \
42-
for key in $GPG_KEYS; do \
43-
gpg --keyserver pool.sks-keyservers.net --recv-keys "$key"; \
44-
done
45-
46-
47-
ENV NPM_CONFIG_LOGLEVEL info
48-
ENV NODE_VERSION 6.3.1
49-
50-
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
51-
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
52-
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
53-
&& grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
54-
&& tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
55-
&& rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt
56-
57-
588
WORKDIR /build
599

6010
# Dependencies
6111
ADD pom.xml /build/pom.xml
6212
RUN ["mvn", "dependency:resolve"]
6313
RUN ["mvn", "verify"]
64-
RUN ["npm", "install"]
6514

6615
# Compile and package jar
6716
ADD src /build/src
@@ -71,6 +20,5 @@ RUN ["mvn", "package"]
7120
ADD server-keystore.jks /build/server-keystore.jks
7221
ADD configuration.xml /build/configuration.xml
7322

74-
#Run msg-node
7523
EXPOSE 9090
7624
CMD ["mvn", "exec:java"]

docs/rest-api/readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## REST API
2+
3+
An HTTP API used by external legacy platforms to interact with Java Hyperties.
4+
5+
### Data Publish
6+
7+
Endpoint: `/requestpub`
8+
9+
This endpoint is used to publish data to be written on a certain Reporter associated to a GUID.
10+

docs/smart-iot-protostub/readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This is a Vertx Protostub component that makes the Bridge between Smart IoT mess
44

55
See full [Smart IOT API spec](https://iot.alticelabs.com/docs/)
66

7+
The device is created with user GUID and stream with the id of the external platform that is feeding the Smart IoT e.g. "edp".
8+
9+
For public entities like Sharing Lx Schools, the procedure is the same. In this case, the Wallet Manager Hyperty is the one that is creating the device and the stream associated to schools.
710

811
14 - 15: invitation contains the user CGUID
912

docs/token-rating/user-activity-rating.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Additional configuration data:
99
tokens_per_walking_km: <integer>,
1010
tokens_per_biking_km: <integer>,
1111
tokens_per_bikesharing_km: <integer>,
12-
tokens_per_evehicle_km: <integer>,
12+
tokens_per_e-driving_km: <integer>,
13+
tokens_per_feedback: <integer>
1314
}
1415
```
1516

@@ -19,11 +20,12 @@ The User Activity Rating Hyperty observes user's activity and reward with tokens
1920
- each biking distance km is rewarded with configured `tokens_per_biking_km`
2021
- each bike sharing distance km is rewarded with configured `tokens_per_bikesharing_km`
2122
- each electric vehicle distance km is rewarded with configured `tokens_per_evehicle_km`
23+
- each feedback provided when submitting google forms (or others) is rewarded with configured `tokens_per_feedback`
2224

2325
![User Activity Rating Arch](user-activity-rating.png)
2426

2527
### Observed Streams
2628

27-
* Citizen User Activity which is a [Context Data Object](https://rethink-project.github.io/specs/datamodel/data-objects/context/readme/?scroll=2564) with types `user_walking_context` or `user_biking_context`
29+
* Citizen User Activity which is a [Context Data Object](https://rethink-project.github.io/specs/datamodel/data-objects/context/readme/?scroll=2564) with types `user_walking_context`, `user_biking_context`, `user_e-driving_context` or `user_giving_feedback_context`
2830

2931

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dev-java-hyperty",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"description": "dev-java-hyperty",
55
"main": "index.js",
66
"directories": {

src/main/java/hyperty/AbstractHyperty.java

Lines changed: 66 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void start() {
5858
this.schemaURL = config().getString("schemaURL");
5959
this.observers = config().getJsonArray("observers");
6060
this.siotStubUrl = config().getString("siot_stub_url");
61-
this.logger = LoggerFactory.getInstance().getLogger();
61+
this.logger = LoggerFactory.getInstance().getLogger();
6262

6363
this.eb = vertx.eventBus();
6464
this.eb.<JsonObject>consumer(this.url, onMessage());
@@ -117,8 +117,8 @@ public Handler<Message<JsonObject>> onMessage() {
117117
logger.debug(logMessage + "New message -> " + message.body().toString());
118118
if (mandatoryFieldsValidator(message)) {
119119

120-
logger.debug(logMessage + "[NewData] -> [Worker]-" + Thread.currentThread().getName()
121-
+ "\n[Data] " + message.body());
120+
logger.debug(logMessage + "[NewData] -> [Worker]-" + Thread.currentThread().getName() + "\n[Data] "
121+
+ message.body());
122122

123123
final JsonObject body = new JsonObject(message.body().toString()).getJsonObject("body");
124124
final String type = new JsonObject(message.body().toString()).getString("type");
@@ -138,8 +138,7 @@ public Handler<Message<JsonObject>> onMessage() {
138138

139139
JsonObject toSearch = new JsonObject().put("identity", identity);
140140

141-
logger.debug(
142-
logMessage + "Search on " + this.collection + " with data" + toSearch.toString());
141+
logger.debug(logMessage + "Search on " + this.collection + " with data" + toSearch.toString());
143142

144143
mongoClient.find(this.collection, toSearch, res -> {
145144
if (res.result().size() != 0) {
@@ -202,6 +201,7 @@ public Future<String> findDataObjectStream(String objURL, String guid) {
202201
Future<String> doStream = Future.future();
203202

204203
mongoClient.find(this.dataObjectsCollection, new JsonObject().put("objURL", objURL), res -> {
204+
System.out.println("dataobject find result(" + objURL + ") :" + res.result().size());
205205
for (int i = 0; i < res.result().size(); i++) {
206206
String currentGuid = res.result().get(i).getJsonObject("metadata").getString("guid");
207207
if (currentGuid.equals(guid)) {
@@ -234,7 +234,8 @@ public void onNotification(JsonObject body) {
234234
Future<String> CheckURL = findDataObjectStream(objURL, guid);
235235
CheckURL.setHandler(asyncResult -> {
236236
if (asyncResult.succeeded()) {
237-
if (CheckURL == null) {
237+
238+
if (asyncResult.result() == null) {
238239
Future<Boolean> persisted = persistDataObjUserURL(streamID, guid, objURL, "reporter");
239240
persisted.setHandler(res -> {
240241
if (res.succeeded()) {
@@ -342,7 +343,8 @@ public Future<Boolean> persistDataObjUserURL(String streamID, String guid, Strin
342343
document.put("guid", guid);
343344
document.put("type", type);
344345

345-
JsonObject toInsert = new JsonObject().put("url", streamID).put("objURL", objURL).put("metadata", document);
346+
JsonObject toInsert = new JsonObject().put("url", streamID).put("objURL", objURL).put("metadata", document)
347+
.put("ratingType", ratingType);
346348
logger.debug("Creating DO entry -> " + toInsert.toString());
347349

348350
mongoClient.save(dataObjectsCollection, toInsert, res2 -> {
@@ -363,10 +365,9 @@ public Future<Boolean> persistDataObjUserURL(String address, String guid, String
363365
document.put("type", type);
364366

365367
JsonObject toFind = new JsonObject().put("url", address);
366-
JsonObject toInsert = new JsonObject().put("url", address)
367-
.put("metadata", document)
368-
.put("ratingType", ratingType);
369-
368+
JsonObject toInsert = new JsonObject().put("url", address).put("metadata", document).put("ratingType",
369+
ratingType);
370+
370371
logger.debug("Creating DO entry -> " + toInsert.toString());
371372
new Thread(() -> {
372373

@@ -379,7 +380,8 @@ public Future<Boolean> persistDataObjUserURL(String address, String guid, String
379380
System.out.println("Setup complete - dataobjects + already exist, but ratingType undefined");
380381
mongoClient.removeDocuments(dataObjectsCollection, toFind, deleteResult -> {
381382
mongoClient.save(dataObjectsCollection, toInsert, resInsert -> {
382-
System.out.println("Setup complete - dataobjects + Insert" + resInsert.result().toString());
383+
System.out.println(
384+
"Setup complete - dataobjects + Insert" + resInsert.result().toString());
383385
dataPersisted.complete(resInsert.succeeded());
384386
});
385387
});
@@ -460,7 +462,6 @@ public boolean validateSource(String from, String address, JsonObject identity,
460462
logger.debug("validating source ... from:" + from + "\nobservers:" + observers.getList().toString()
461463
+ "\nourUserURL:" + this.identity.getJsonObject("userProfile").getString("userURL") + "\nCOLLECTION:"
462464
+ collection);
463-
464465

465466
return true;
466467

@@ -542,90 +543,84 @@ public boolean mandatoryFieldsValidator(Message<JsonObject> message) {
542543
return true;
543544

544545
}
545-
546-
547-
546+
548547
public void resumeDataObjects(String ratingType) {
549-
550-
JsonObject tofind = new JsonObject().put("ratingType", ratingType);
551-
logger.debug("Resuming dataobjects ratingType-> " + ratingType);
552-
mongoClient.find(dataObjectsCollection, tofind, allDataObjects -> {
553-
logger.debug("GetAllDataObjects complete - " + allDataObjects.result().size());
554-
for (int i = 0; i < allDataObjects.result().size(); i++) {
555-
String dataObjectUrl = allDataObjects.result().get(i).getString("url");
556-
onChanges(dataObjectUrl);
557-
}
558-
});
559-
}
548+
549+
JsonObject tofind = new JsonObject().put("ratingType", ratingType);
550+
logger.debug("Resuming dataobjects ratingType-> " + ratingType);
551+
mongoClient.find(dataObjectsCollection, tofind, allDataObjects -> {
552+
logger.debug("GetAllDataObjects complete - " + allDataObjects.result().size());
553+
for (int i = 0; i < allDataObjects.result().size(); i++) {
554+
String dataObjectUrl = allDataObjects.result().get(i).getString("url");
555+
if(allDataObjects.result().get(i).containsKey("objURL")) {
556+
onChanges(allDataObjects.result().get(i).getString("objURL"));
557+
} else {
558+
onChanges(dataObjectUrl);
559+
}
560+
561+
}
562+
});
563+
}
560564

561565
public void cleanDuplicatedDataObjects() {
562-
566+
563567
mongoClient.find(dataObjectsCollection, new JsonObject(), resultHandler -> {
564-
565-
566-
567-
//all documents
568+
569+
// all documents
568570
List<JsonObject> dataObjectsArray = resultHandler.result();
569571
logger.info("All dos size:" + dataObjectsArray.size());
570-
571-
//to fill with single url of each dataobject
572+
573+
// to fill with single url of each dataobject
572574
List<String> dataObjectsUrl = new ArrayList<String>();
573-
575+
574576
if (dataObjectsArray.size() > 0) {
575577
int i;
576578
for (i = 0; i < dataObjectsArray.size(); i++) {
577-
579+
578580
JsonObject currentDO = dataObjectsArray.get(i);
579581
String url = currentDO.getString("url");
580-
582+
581583
if (!currentDO.containsKey("objURL") && !dataObjectsUrl.contains(url)) {
582-
//add to list
584+
// add to list
583585
dataObjectsUrl.add(url);
584-
586+
585587
JsonObject toRemove = new JsonObject().put("url", url);
586-
587-
588-
//JsonObject document = currentDO.getJsonObject("metadata");
589588

590-
//JsonObject toAdd = new JsonObject().put("url", url)
591-
// .put("metadata", document);
589+
// JsonObject document = currentDO.getJsonObject("metadata");
590+
591+
// JsonObject toAdd = new JsonObject().put("url", url)
592+
// .put("metadata", document);
592593
currentDO.remove("_id");
593-
594+
594595
mongoClient.removeDocuments(dataObjectsCollection, toRemove, deleteResult -> {
595596
mongoClient.save(dataObjectsCollection, currentDO, resInsert -> {
596597
logger.info("Setup complete - dataobjects + Insert" + resInsert.result().toString());
597598
});
598599
});
599-
600+
600601
}
601602
}
602603
logger.info("single do size:" + dataObjectsUrl.size());
603604
}
604-
605-
606-
/*
607-
mongoClient.find(dataObjectsCollection, new JsonObject(), res2 -> {
608-
if (res2.result().size() > 0) {
609-
if (res2.result().get(0).containsKey("ratingType")) {
610-
System.out.println("Setup complete - dataobjects + already exist");
611-
dataPersisted.complete(true);
612-
} else {
613-
System.out.println("Setup complete - dataobjects + already exist, but ratingType undefined");
614-
mongoClient.removeDocuments(dataObjectsCollection, toFind, deleteResult -> {
615-
mongoClient.save(dataObjectsCollection, toInsert, resInsert -> {
616-
System.out.println("Setup complete - dataobjects + Insert" + resInsert.result().toString());
617-
dataPersisted.complete(resInsert.succeeded());
618-
});
619-
});
620-
}
621-
622-
} else {
623-
mongoClient.save(dataObjectsCollection, toInsert, resInsert -> {
624-
System.out.println("Setup complete - dataobjects + Insert" + resInsert.result().toString());
625-
dataPersisted.complete(resInsert.succeeded());
626-
});
627-
}
628-
});*/
605+
606+
/*
607+
* mongoClient.find(dataObjectsCollection, new JsonObject(), res2 -> { if
608+
* (res2.result().size() > 0) { if
609+
* (res2.result().get(0).containsKey("ratingType")) {
610+
* System.out.println("Setup complete - dataobjects + already exist");
611+
* dataPersisted.complete(true); } else { System.out.
612+
* println("Setup complete - dataobjects + already exist, but ratingType undefined"
613+
* ); mongoClient.removeDocuments(dataObjectsCollection, toFind, deleteResult ->
614+
* { mongoClient.save(dataObjectsCollection, toInsert, resInsert -> {
615+
* System.out.println("Setup complete - dataobjects + Insert" +
616+
* resInsert.result().toString());
617+
* dataPersisted.complete(resInsert.succeeded()); }); }); }
618+
*
619+
* } else { mongoClient.save(dataObjectsCollection, toInsert, resInsert -> {
620+
* System.out.println("Setup complete - dataobjects + Insert" +
621+
* resInsert.result().toString());
622+
* dataPersisted.complete(resInsert.succeeded()); }); } });
623+
*/
629624
});
630625
}
631626
}

0 commit comments

Comments
 (0)