2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.model;
23 import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import java.io.IOException;
27 import java.util.Objects;
28 import java.util.UUID;
29 import javax.persistence.Column;
30 import javax.persistence.Entity;
31 import javax.persistence.EnumType;
32 import javax.persistence.Enumerated;
33 import javax.persistence.Id;
34 import javax.persistence.Table;
35 import javax.persistence.Transient;
36 import org.hibernate.annotations.DynamicUpdate;
37 import org.hibernate.annotations.SelectBeforeUpdate;
38 import org.hibernate.annotations.Type;
39 import org.onap.vid.exceptions.GenericUncheckedException;
40 import org.onap.vid.job.Job;
41 import org.onap.vid.job.JobException;
42 import org.onap.vid.mso.rest.AsyncRequestStatus;
47 @Table(name = "vid_resource_info")
48 public class ResourceInfo extends VidBaseEntity {
50 private String trackById;
51 private UUID rootJobId;
52 private String instanceId;
53 private Job.JobStatus jobStatus;
54 private AsyncRequestStatus errorMessage;
56 public ResourceInfo(){}
58 public ResourceInfo(String trackById, UUID rootJobId, String instanceId, Job.JobStatus jobStatus, AsyncRequestStatus errorMessage) {
59 this.trackById = trackById;
60 this.rootJobId = rootJobId;
61 this.instanceId = instanceId;
62 this.jobStatus = jobStatus;
63 this.errorMessage = errorMessage;
67 @Column(name = "TRACK_BY_ID", columnDefinition = "CHAR(36)")
68 public String getTrackById() {
72 @Column(name = "ROOT_JOB_ID", columnDefinition = "CHAR(36)")
73 @Type(type="org.hibernate.type.UUIDCharType")
74 public UUID getRootJobId() {
78 @Column(name="JOB_STATUS")
79 @Enumerated(EnumType.STRING)
80 public Job.JobStatus getJobStatus() {
84 @Column(name="INSTANCE_ID")
85 public String getInstanceId() {
89 public void setTrackById(String trackById) {
90 this.trackById = trackById;
93 public void setRootJobId(UUID rootJobId) {
94 this.rootJobId = rootJobId;
97 public void setInstanceId(String instanceId) {
98 this.instanceId = instanceId;
100 public void setJobStatus(Job.JobStatus jobStatus) {
101 this.jobStatus = jobStatus;
104 @Column(name = "ERROR_MESSAGE", columnDefinition = "VARCHAR(30000)")
105 public String getErrorMessageRaw() {
107 return JACKSON_OBJECT_MAPPER.writeValueAsString(errorMessage);
108 } catch (JsonProcessingException e) {
109 throw new GenericUncheckedException(e);
113 public void setErrorMessageRaw(String failedMessage) {
115 this.errorMessage = JACKSON_OBJECT_MAPPER.readValue(failedMessage, AsyncRequestStatus.class);
116 } catch (IOException e) {
117 throw new JobException("Error parsing mso failed message", rootJobId, e);
122 public AsyncRequestStatus getErrorMessage() {
123 return this.errorMessage;
126 public void setErrorMessage(AsyncRequestStatus errorMessage) {
127 this.errorMessage = errorMessage;
131 public boolean equals(Object o) {
132 if (this == o) return true;
133 if (o == null || getClass() != o.getClass()) return false;
134 ResourceInfo that = (ResourceInfo) o;
135 return Objects.equals(trackById, that.trackById) &&
136 Objects.equals(instanceId, that.instanceId) &&
137 jobStatus == that.jobStatus;
141 public int hashCode() {
142 return Objects.hash(trackById, instanceId, jobStatus);