Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@

import de.dentrassi.kapua.smarthome.internal.Configuration;


@Component(properties = "OSGI-INF/persistence.properties")
@Designate(ocd = Configuration.class)
public class PersistenceServiceImpl implements PersistenceService {

private static final Logger logger = LoggerFactory.getLogger(PersistenceServiceImpl.class);

private Client client;
private Application app;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static java.util.Collections.unmodifiableMap;

import java.time.Instant;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand All @@ -27,19 +28,20 @@ public class Payload {

public static class Builder {

private Instant timestamp;
// private Instant timestamp;
Date timestamp;

private Map<String, Object> values = new HashMap<String, Object>();

public Builder() {
this.timestamp = Instant.now();
this.timestamp = new Date();
}

public Instant timestamp() {
public Date timestamp() {
return this.timestamp;
}

public Builder timestamp(final Instant timestamp) {
public Builder timestamp(final Date timestamp) {
Objects.requireNonNull(timestamp);

this.timestamp = timestamp;
Expand Down Expand Up @@ -71,15 +73,15 @@ public Payload build() {
}
}

private final Instant timestamp;
private final Date timestamp;
private final Map<String, ?> values;

private Payload(final Instant timestamp, final Map<String, ?> values, final boolean cloneValues) {
private Payload(final Date timestamp, final Map<String, ?> values, final boolean cloneValues) {
this.timestamp = timestamp;
this.values = unmodifiableMap(cloneValues ? new HashMap<>(values) : values);
}

public Instant getTimestamp() {
public Date getTimestamp() {
return this.timestamp;
}

Expand All @@ -95,23 +97,23 @@ public String toString() {
public static Payload of(final String key, final Object value) {
Objects.requireNonNull(key);

return new Payload(now(), singletonMap(key, value), false);
return new Payload(new Date(), singletonMap(key, value), false);
}

public static Payload of(final Map<String, ?> values) {
Objects.requireNonNull(values);

return new Payload(now(), values, true);
return new Payload(new Date(), values, true);
}

public static Payload of(final Instant timestamp, final String key, final Object value) {
public static Payload of(final Date timestamp, final String key, final Object value) {
Objects.requireNonNull(timestamp);
Objects.requireNonNull(key);

return new Payload(timestamp, singletonMap(key, value), false);
}

public static Payload of(final Instant timestamp, final Map<String, ?> values) {
public static Payload of(final Date timestamp, final Map<String, ?> values) {
Objects.requireNonNull(timestamp);
Objects.requireNonNull(values);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.time.Instant;
import java.util.Collections;
import java.util.Date;

import org.junit.Assert;
import org.junit.Test;
Expand All @@ -36,7 +37,7 @@ public void testNull3() {

@Test(expected = NullPointerException.class)
public void testNull4() {
Payload.of((Instant) null, null);
Payload.of((Date) null, null);
}

@Test
Expand All @@ -46,7 +47,7 @@ public void test1() {
Assert.assertNotNull(p);
Assert.assertEquals(1, p.getValues().size());
Assert.assertEquals(1, p.getValues().get("foo"));
Assert.assertTrue(!Instant.now().isBefore(p.getTimestamp()));
Assert.assertTrue(!new Date().before(p.getTimestamp()));
}

@Test
Expand All @@ -56,37 +57,37 @@ public void test2() {
Assert.assertNotNull(p);
Assert.assertEquals(1, p.getValues().size());
Assert.assertEquals(1, p.getValues().get("foo"));
Assert.assertTrue(!Instant.now().isBefore(p.getTimestamp()));
Assert.assertTrue(!new Date().before(p.getTimestamp()));
}

@Test
public void test3() {
Payload p = Payload.of(Instant.now(), "foo", 1);
Payload p = Payload.of(new Date() , "foo", 1);

Assert.assertNotNull(p);
Assert.assertEquals(1, p.getValues().size());
Assert.assertEquals(1, p.getValues().get("foo"));
Assert.assertTrue(!Instant.now().isBefore(p.getTimestamp()));
Assert.assertTrue(!new Date().before(p.getTimestamp()));
}

@Test
public void test4() {
Payload p = Payload.of(Instant.now(), Collections.singletonMap("foo", 1));
Payload p = Payload.of(new Date(), Collections.singletonMap("foo", 1));

Assert.assertNotNull(p);
Assert.assertEquals(1, p.getValues().size());
Assert.assertEquals(1, p.getValues().get("foo"));
Assert.assertTrue(!Instant.now().isBefore(p.getTimestamp()));
Assert.assertTrue(!new Date().before(p.getTimestamp()));
}

@Test
public void testBuilder1() {
final Payload p = new Payload.Builder().timestamp(Instant.now()).put("foo", 1).build();
final Payload p = new Payload.Builder().timestamp(new Date()).put("foo", 1).build();

Assert.assertNotNull(p);
Assert.assertEquals(1, p.getValues().size());
Assert.assertEquals(1, p.getValues().get("foo"));
Assert.assertTrue(!Instant.now().isBefore(p.getTimestamp()));
Assert.assertTrue(!new Date().before(p.getTimestamp()));
}

@Test(expected = NullPointerException.class)
Expand All @@ -106,11 +107,11 @@ public void testBuilder4() {

@Test
public void testBuilder5() {
final Payload p = new Payload.Builder().timestamp(Instant.now()).values(Collections.singletonMap("foo", 1)).build();
final Payload p = new Payload.Builder().timestamp(new Date()).values(Collections.singletonMap("foo", 1)).build();

Assert.assertNotNull(p);
Assert.assertEquals(1, p.getValues().size());
Assert.assertEquals(1, p.getValues().get("foo"));
Assert.assertTrue(!Instant.now().isBefore(p.getTimestamp()));
Assert.assertTrue(!new Date().before(p.getTimestamp()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ByteBuffer encode(final Payload payload, final ByteBuffer buffer) throws
Objects.requireNonNull(payload);

final KuraPayloadProto.KuraPayload.Builder builder = KuraPayload.newBuilder();
builder.setTimestamp(payload.getTimestamp().toEpochMilli());
builder.setTimestamp(payload.getTimestamp().getTime());
Metrics.buildMetrics(builder, payload.getValues());

final byte[] data = builder.build().toByteArray();
Expand All @@ -68,7 +68,7 @@ public Payload decode(final ByteBuffer buffer) throws Exception {

final KuraPayload payload = KuraPayload.parseFrom(Buffers.toByteArray(buffer));
final Map<String, Object> values = Metrics.extractMetrics(payload);
return Payload.of(Instant.ofEpochMilli(payload.getTimestamp()), values);
return Payload.of(payload.getTimestamp()+"", values);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,14 @@ private void sendBirthCertificate() {
provider.provideData(values);
}

values.put("application_ids", String.join(",", this.applications));
//values.put("application_ids", String.join(",", this.applications));
StringBuffer sb = new StringBuffer( "\\b(" );
String del = "";
for( String t: this.applications ){
sb.append(del).append( t );
del = ",";
}
values.put("application_ids", sb.toString());//String.join(",", this.applications));

// build payload

Expand Down