import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
+
import org.onap.clamp.loop.Loop;
/**
- *
* This class holds the logs created by the Clamp Backend. The Instant is always
* rounded to the nearest second as the nano seconds can't be stored in the
* database. The logs can be therefore exposed to the UI or the client doing
*/
@Entity
@Table(name = "loop_logs")
-public class LoopLog implements Serializable {
+public class LoopLog implements Serializable, Comparable<LoopLog> {
/**
- *
+ * The serial version ID.
*/
private static final long serialVersionUID = 1988276670074437631L;
private LogType logType;
@Expose
- @Column(name = "message", nullable = false)
+ @Column(name = "log_component", nullable = false)
+ private String logComponent;
+
+ @Expose
+ @Column(name = "message", columnDefinition = "MEDIUMTEXT", nullable = false)
private String message;
@ManyToOne(fetch = FetchType.LAZY)
@Column(name = "log_instant", nullable = false)
private Instant logInstant = Instant.now().truncatedTo(ChronoUnit.SECONDS);
+ public LoopLog() {
+ }
+
+ public LoopLog(String message, LogType logType, String logComponent, Loop loop) {
+ this.message = message;
+ this.logType = logType;
+ this.loop = loop;
+ this.logComponent = logComponent;
+ }
+
public Long getId() {
return id;
}
this.logInstant = logInstant.truncatedTo(ChronoUnit.SECONDS);
}
+ public String getLogComponent() {
+ return logComponent;
+ }
+
+ public void setLogComponent(String logComponent) {
+ this.logComponent = logComponent;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
LoopLog other = (LoopLog) obj;
if (id == null) {
- if (other.id != null)
+ if (other.id != null) {
return false;
- } else if (!id.equals(other.id))
+ }
+ } else if (!id.equals(other.id)) {
return false;
+ }
return true;
}
+ @Override
+ public int compareTo(LoopLog arg0) {
+ // Reverse it, so that by default we have the latest
+ if (getId() == null) {
+ return 1;
+ }
+ if (arg0.getId() == null) {
+ return -1;
+ }
+
+ return arg0.getId().compareTo(this.getId());
+
+ }
+
}