Skip to content

Commit

Permalink
Merge pull request #72 from reTHINK-project/develop
Browse files Browse the repository at this point in the history
Develop to master
  • Loading branch information
luistduarte authored Mar 15, 2019
2 parents 70e5a75 + 4c55802 commit 02875ef
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 143 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dev-java-hyperty",
"version": "0.7.0",
"version": "0.8.0",
"description": "dev-java-hyperty",
"main": "index.js",
"directories": {
Expand Down
41 changes: 25 additions & 16 deletions src/main/java/hyperty/CRMHyperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,11 @@ private void ticketUpdateClosed(JsonObject msg) {
if (asyncResult.succeeded()) {
if (asyncResult.result().equals("")) {
// agent code not registered
logger.debug(logMessage + "ticketUpdateClosed(): no agent for user " + participantHypertyURL);
return;
logger.debug(logMessage + "ticketUpdateClosed(): no agent for user (" + participantHypertyURL + ")" + participantHypertyURL);
if (participantHypertyURL != null) {
return;
}

}
JsonObject query = new JsonObject().put("url", msgobjectURL);
mongoClient.find(ticketsCollection, query, res -> {
Expand All @@ -518,19 +521,22 @@ private void ticketUpdateClosed(JsonObject msg) {
logger.debug(logMessage + "ticketUpdateClosed() updated: " + document);
});
});

JsonObject agentQuery = new JsonObject().put("code", asyncResult.result());
// update agent
mongoClient.find(agentsCollection, agentQuery, res -> {
JsonArray results = new JsonArray(res.result());
JsonObject agent = results.getJsonObject(0);
JsonArray tickets = agent.getJsonArray("tickets");
tickets.remove(tickets.size() - 1);
agent.put(openedTickets, agent.getInteger(openedTickets) - 1);
JsonObject document = new JsonObject(agent.toString());
mongoClient.findOneAndReplace(agentsCollection, agentQuery, document, id -> {

if (! asyncResult.result().equals("")) {
JsonObject agentQuery = new JsonObject().put("code", asyncResult.result());
// update agent
mongoClient.find(agentsCollection, agentQuery, res -> {
JsonArray results = new JsonArray(res.result());
JsonObject agent = results.getJsonObject(0);
JsonArray tickets = agent.getJsonArray("tickets");
tickets.remove(tickets.size() - 1);
agent.put(openedTickets, agent.getInteger(openedTickets) - 1);
JsonObject document = new JsonObject(agent.toString());
mongoClient.findOneAndReplace(agentsCollection, agentQuery, document, id -> {
});
});
});
}

} else {
// oh ! we have a problem...
}
Expand Down Expand Up @@ -588,6 +594,8 @@ private Future<String> getCodeForAgent(String agentHypertyURL) {
if (results.size() > 0) {
JsonObject agent = results.getJsonObject(0);
getCodeForAgent.complete(agent.getString("code"));
} else {
getCodeForAgent.complete("");
}
});

Expand Down Expand Up @@ -647,11 +655,12 @@ private void forwardMessage(JsonObject message, JsonObject ticket) {

for (Object entry : results) {
JsonObject agent = (JsonObject) entry;
JsonObject messagecopy = new JsonObject(message.toString());
String address = agent.getString("address");
String guid = agent.getString("user");
String code = agent.getString("code");
message.put("to", address);
send(guid, message, reply -> {
messagecopy.put("to", address);
send(guid, messagecopy, reply -> {
});

// , reply -> {
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/protostub/SmartIotProtostub.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,18 @@ private Handler<Message<JsonObject>> onNewPost() {
String streamName = currentObj.getString("streamName");
String deviceID = currentObj.getString("deviceId");
String value = currentObj.getString("data");
String valReplaced = value.replace(",", ".");


String date = currentObj.getString("receivedAt");

Future<JsonObject> objURLFuture = findStream(currentObj.getString("streamId"));
objURLFuture.setHandler(asyncResult -> {
JsonObject dataObject = asyncResult.result();
String objURL = dataObject.getString("objURL");

if (streamName.equals("edp")) {

if (dataObject != null && dataObject.containsKey("objURL")) {
String objURL = dataObject.getString("objURL");
if (streamName.equals("edp")) {
String valReplaced = value.replace(",", ".");
Float fValue = Float.parseFloat(valReplaced);
int iValue = Math.round(fValue);

Expand All @@ -232,6 +234,13 @@ private Handler<Message<JsonObject>> onNewPost() {
vertx.eventBus().publish(changesObj, allData);
}
} else if (streamName.equals("mobie")) {

JsonObject objAdaptReceived = new JsonObject(value);
System.out.println("objAdaptReceived:" + objAdaptReceived.toString());
int valReplaced = objAdaptReceived.getJsonObject("mobie").getInteger("value");

//JsonObject objAdaptReceived = new JsonObject(valReplaced);
//System.out.println("data:" + objAdaptReceived.toString());
JsonArray valuestoSend = new JsonArray();
JsonObject data = new JsonObject();

Expand All @@ -241,10 +250,11 @@ private Handler<Message<JsonObject>> onNewPost() {
data.put("startTime", date);
data.put("endTime", date);

Double value_kw = Double.parseDouble(valReplaced);
//Double value_kw = Double.parseDouble(valReplaced);


// 12kWh/100km
data.put("value", value_kw);
data.put("value", (double) valReplaced);

valuestoSend.add(data);

Expand All @@ -254,6 +264,8 @@ private Handler<Message<JsonObject>> onNewPost() {
vertx.eventBus().publish(changesObj, valuestoSend);
}
}

}
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/runHyperties/StartJavaHyperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ public void start() throws Exception {
configWalletManager.put("siot_stub_url", smartIotProtostubUrl);
configWalletManager.put("rankingTimer", 30000);
configWalletManager.put("onReadMaxTransactions", 100);
configWalletManager.put("engageRating", 50);


// public wallets
String wallet0Address = "school0-wallet";
Expand Down
1 change: 1 addition & 0 deletions src/main/java/tokenRating/EnergySavingRatingHyperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ private void transferToPublicWallet(int causeReductionPercentage, String id) {
transaction.put("value", causeReductionPercentage * 5);
transaction.put("date", DateUtilsHelper.getCurrentDateAsISO8601());
transaction.put("bonus", true);
transaction.put("wallet2bGranted", getPublicWallet.result().getString("address"));
JsonObject data = new JsonObject();
data.put("value", causeReductionPercentage);
transaction.put("data", data);
Expand Down
Loading

0 comments on commit 02875ef

Please sign in to comment.