2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.loop.log;
26 import com.google.gson.annotations.Expose;
28 import java.io.Serializable;
29 import java.time.Instant;
30 import java.time.temporal.ChronoUnit;
32 import javax.persistence.Column;
33 import javax.persistence.Entity;
34 import javax.persistence.EnumType;
35 import javax.persistence.Enumerated;
36 import javax.persistence.FetchType;
37 import javax.persistence.GeneratedValue;
38 import javax.persistence.GenerationType;
39 import javax.persistence.Id;
40 import javax.persistence.JoinColumn;
41 import javax.persistence.ManyToOne;
42 import javax.persistence.Table;
44 import org.onap.clamp.loop.Loop;
47 * This class holds the logs created by the Clamp Backend. The Instant is always
48 * rounded to the nearest second as the nano seconds can't be stored in the
49 * database. The logs can be therefore exposed to the UI or the client doing
50 * some GET Loop on the backend.
54 @Table(name = "loop_logs")
55 public class LoopLog implements Serializable {
57 * The serial version ID.
59 private static final long serialVersionUID = 1988276670074437631L;
63 @GeneratedValue(strategy = GenerationType.AUTO)
67 @Column(name = "log_type", nullable = false)
68 @Enumerated(EnumType.STRING)
69 private LogType logType;
72 @Column(name = "message", nullable = false)
73 private String message;
75 @ManyToOne(fetch = FetchType.LAZY)
76 @JoinColumn(name = "loop_id", nullable = false)
80 @Column(name = "log_instant", nullable = false)
81 private Instant logInstant = Instant.now().truncatedTo(ChronoUnit.SECONDS);
86 public LoopLog(String message, LogType logType, Loop loop) {
87 this.message = message;
88 this.logType = logType;
96 public void setId(Long id) {
100 public LogType getLogType() {
104 public void setLogType(LogType logType) {
105 this.logType = logType;
108 public String getMessage() {
112 public void setMessage(String message) {
113 this.message = message;
116 public Loop getLoop() {
120 public void setLoop(Loop loop) {
124 public Instant getLogInstant() {
128 public void setLogInstant(Instant logInstant) {
129 this.logInstant = logInstant.truncatedTo(ChronoUnit.SECONDS);
133 public int hashCode() {
134 final int prime = 31;
136 result = prime * result + ((id == null) ? 0 : id.hashCode());
141 public boolean equals(Object obj) {
148 if (getClass() != obj.getClass()) {
151 LoopLog other = (LoopLog) obj;
153 if (other.id != null) {
156 } else if (!id.equals(other.id)) {