Created
March 20, 2020 08:47
-
-
Save nabam/ef0ae0db69e6918ba00a8d28977cff7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.metrologicgroup.x4_events_ingestion.model; | |
import com.fasterxml.jackson.annotation.JsonFormat; | |
import com.fasterxml.jackson.annotation.JsonFormat.Shape; | |
import com.fasterxml.jackson.annotation.JsonProperty; | |
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | |
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | |
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | |
import com.google.auto.value.AutoValue; | |
import java.io.Serializable; | |
import java.time.LocalDateTime; | |
import javax.annotation.Nullable; | |
import org.apache.avro.reflect.AvroName; | |
@AutoValue | |
@JsonDeserialize(builder = AutoValue_X4StateEvent.Builder.class) | |
public abstract class X4StateEvent implements Serializable { | |
@JsonFormat(shape = Shape.OBJECT) | |
public enum State { | |
NOT_CONNECTED(0, "Not Connected"), | |
CONNECTED(1, "Connected"), | |
EXECUTION_IN_PROGRESS(2, "Execution in Progress"), | |
ERROR(3, "Error"); | |
@JsonProperty("id") | |
private int value; | |
@JsonProperty("english_name") | |
private String englishName; | |
private State(int value, String englishName) { | |
this.value = value; | |
this.englishName = englishName; | |
} | |
public static State fromId(int id) { | |
for (State s : State.values()) { | |
if (s.value == id) { | |
return s; | |
} | |
} | |
return null; | |
} | |
} | |
@JsonProperty("timestamp") | |
@JsonSerialize(using = LocalDateTimeSerializer.class) | |
@JsonFormat(shape = Shape.STRING) | |
public abstract LocalDateTime timestamp(); | |
@JsonProperty("gateway_timestamp") | |
@JsonSerialize(using = LocalDateTimeSerializer.class) | |
@JsonFormat(shape = Shape.STRING) | |
public abstract LocalDateTime gatewayTimestamp(); | |
@JsonProperty("device_id") | |
public abstract String deviceId(); | |
@JsonProperty("device_state") | |
@Nullable | |
public abstract State deviceState(); | |
@AutoValue.Builder | |
public interface Builder { | |
@JsonProperty("timestamp") | |
Builder timestamp(LocalDateTime time); | |
@JsonProperty("gateway_timestamp") | |
Builder gatewayTimestamp(LocalDateTime time); | |
@JsonProperty("device_id") | |
Builder deviceId(String id); | |
@JsonProperty("device_state") | |
Builder deviceState(State state); | |
X4StateEvent build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment