Skip to content

Commit

Permalink
Java implementation for real-time notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-Winter-Software-AG committed Feb 12, 2024
1 parent 41c5ecd commit 321c598
Show file tree
Hide file tree
Showing 11 changed files with 675 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cumulocity.model;

import com.cumulocity.model.NotificationConverters.*;
import com.cumulocity.model.audit.AuditChangeValueConverter;
import org.joda.time.DateTime;
import org.svenson.*;
Expand Down Expand Up @@ -72,6 +73,11 @@ private static List<TypeConverter> defaultTypeConverters() {
converters.add(new IDListTypeConverter());
converters.add(new DateConverter());
converters.add(new AuditChangeValueConverter());
converters.add(new DeletedManagedObjectConverter());
converters.add(new DeletedMeasurementConverter());
converters.add(new DeletedEventConverter());
converters.add(new DeletedAlarmConverter());
converters.add(new DeletedOperationConverter());
return converters;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.cumulocity.model;

import org.svenson.converter.TypeConverter;

import com.cumulocity.model.idtype.GId;
import com.cumulocity.rest.representation.alarm.AlarmRepresentation;
import com.cumulocity.rest.representation.event.EventRepresentation;
import com.cumulocity.rest.representation.inventory.ManagedObjectRepresentation;
import com.cumulocity.rest.representation.measurement.MeasurementRepresentation;
import com.cumulocity.rest.representation.operation.OperationRepresentation;

public class NotificationConverters {

public static class DeletedManagedObjectConverter implements TypeConverter {

@Override
public Object fromJSON(Object o) {
if (o instanceof String) {
ManagedObjectRepresentation wrapper = new ManagedObjectRepresentation();
wrapper.set(new GId((String)o));
o = wrapper;
}
return o;
}

@Override
public Object toJSON(Object o) { // not needed at all
return o;
}

}

public static class DeletedMeasurementConverter implements TypeConverter {

@Override
public Object fromJSON(Object o) {
if (o instanceof String) {
MeasurementRepresentation wrapper = new MeasurementRepresentation();
wrapper.set(new GId((String)o));
o = wrapper;
}
return o;
}

@Override
public Object toJSON(Object o) { // not needed at all
return o;
}

}

public static class DeletedEventConverter implements TypeConverter {

@Override
public Object fromJSON(Object o) {
if (o instanceof String) {
EventRepresentation wrapper = new EventRepresentation();
wrapper.set(new GId((String)o));
o = wrapper;
}
return o;
}

@Override
public Object toJSON(Object o) { // not needed at all
return o;
}

}

public static class DeletedAlarmConverter implements TypeConverter {

@Override
public Object fromJSON(Object o) {
if (o instanceof String) {
AlarmRepresentation wrapper = new AlarmRepresentation();
wrapper.set(new GId((String)o));
o = wrapper;
}
return o;
}

@Override
public Object toJSON(Object o) { // not needed at all
return o;
}

}

public static class DeletedOperationConverter implements TypeConverter {

@Override
public Object fromJSON(Object o) {
if (o instanceof String) {
OperationRepresentation wrapper = new OperationRepresentation();
wrapper.set(new GId((String)o));
o = wrapper;
}
return o;
}

@Override
public Object toJSON(Object o) { // not needed at all
return o;
}

}

}
Loading

0 comments on commit 321c598

Please sign in to comment.