Merge branch 'feature/device-service' of https://github.com/jazzm0/microservices-demo into feature/device-service

This commit is contained in:
Elisa Stelling 2019-12-11 11:58:03 +01:00
commit b99f7cd890
2 changed files with 18 additions and 4 deletions

View file

@ -61,14 +61,18 @@ public class Device {
@JsonIgnore @JsonIgnore
public void changeHealthScore(int delta) { public void changeHealthScore(int delta) {
int oldScore = healthScore;
if (healthScore >= 1) { if (healthScore >= 1) {
healthScore += delta; healthScore += delta;
if (healthScore > 150) if (healthScore > 150)
healthScore /= 10; healthScore /= 10;
} else {
healthScore = 0;
} }
messages.add(new DeviceEvent(id, owner, color, born, healthScore, Instant.now()));
if (healthScore < 1) {
healthScore = 0;
messages.add(new DeviceEvent(id, owner, color, born, healthScore, oldScore, Instant.now()));
} else
messages.add(new DeviceEvent(id, owner, color, born, healthScore, null, Instant.now()));
} }
@JsonIgnore @JsonIgnore

View file

@ -1,6 +1,7 @@
package com.sap.tamagotchi.model; package com.sap.tamagotchi.model;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.Instant; import java.time.Instant;
@ -18,15 +19,18 @@ public class DeviceEvent implements IoTMessage {
private final Instant born; private final Instant born;
@JsonProperty("healthScore") @JsonProperty("healthScore")
private final Integer healthScore; private final Integer healthScore;
@JsonProperty("lastHealthScore")
private final Integer lastHealthScore;
@JsonProperty("eventTime") @JsonProperty("eventTime")
private final Instant eventTime; private final Instant eventTime;
public DeviceEvent(String id, String owner, Color color, Instant born, Integer healthScore, Instant eventTime) { public DeviceEvent(String id, String owner, Color color, Instant born, Integer healthScore, Integer lastHealthScore, Instant eventTime) {
this.id = id; this.id = id;
this.owner = owner; this.owner = owner;
this.color = color; this.color = color;
this.born = born; this.born = born;
this.healthScore = healthScore; this.healthScore = healthScore;
this.lastHealthScore = lastHealthScore;
this.eventTime = eventTime; this.eventTime = eventTime;
} }
@ -55,6 +59,12 @@ public class DeviceEvent implements IoTMessage {
return healthScore; return healthScore;
} }
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonProperty("lastHealthScore")
public Integer getLastHealthScore() {
return lastHealthScore;
}
@JsonProperty("eventTime") @JsonProperty("eventTime")
public String getEventTime() { public String getEventTime() {
return eventTime.toString(); return eventTime.toString();