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.dao;
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.Id;
32 import javax.persistence.Table;
33 import javax.persistence.Transient;
34 import org.hibernate.annotations.DynamicUpdate;
35 import org.hibernate.annotations.SelectBeforeUpdate;
36 import org.hibernate.annotations.Type;
37 import org.onap.vid.model.VidBaseEntity;
38 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
44 @Table(name = "vid_job_request")
45 public class JobRequest extends VidBaseEntity {
48 private ServiceInstantiation request;
51 public JobRequest(UUID jobId, ServiceInstantiation request) {
53 this.request = request;
60 @Column(name = "JOB_ID", columnDefinition = "CHAR(36)")
61 @Type(type = "org.hibernate.type.UUIDCharType")
62 public UUID getJobId() {
66 public void setJobId(UUID jobId) {
71 public ServiceInstantiation getRequest() {
75 public void setRequest(ServiceInstantiation request) {
76 this.request = request;
79 //the columnDefinition is used only in UT
80 @Column(name = "REQUEST", columnDefinition = "VARCHAR(30000)")
81 public String getRequestRaw() {
83 return JACKSON_OBJECT_MAPPER.writeValueAsString(request);
84 } catch (JsonProcessingException e) {
85 throw new RuntimeException(e);
89 public void setRequestRaw(String raw) {
91 this.request = JACKSON_OBJECT_MAPPER.readValue(raw, ServiceInstantiation.class);
92 } catch (IOException e) {
93 throw new RuntimeException(e);
98 public boolean equals(Object o) {
99 if (this == o) return true;
100 if (!(o instanceof JobRequest)) return false;
101 JobRequest that = (JobRequest) o;
102 return Objects.equals(getJobId(), that.getJobId()) &&
103 Objects.equals(getRequest(), that.getRequest());
107 public int hashCode() {
108 return Objects.hash(getJobId(), getRequest());