Domain model change
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / DomainVo.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ===================================================================
9  *
10  * Unless otherwise specified, all software contained herein is licensed
11  * under the Apache License, Version 2.0 (the "License");
12  * you may not use this software except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *             http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  * Unless otherwise specified, all documentation contained herein is licensed
24  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25  * you may not use this documentation except in compliance with the License.
26  * You may obtain a copy of the License at
27  *
28  *             https://creativecommons.org/licenses/by/4.0/
29  *
30  * Unless required by applicable law or agreed to in writing, documentation
31  * distributed under the License is distributed on an "AS IS" BASIS,
32  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33  * See the License for the specific language governing permissions and
34  * limitations under the License.
35  *
36  * ============LICENSE_END============================================
37  *
38  *
39  */
40
41 package org.onap.portal.domain.db;
42
43 import java.io.ByteArrayInputStream;
44 import java.io.ByteArrayOutputStream;
45 import java.io.ObjectInputStream;
46 import java.io.ObjectOutputStream;
47 import java.io.Serializable;
48 import java.time.LocalDateTime;
49 import java.util.Set;
50 import javax.persistence.CascadeType;
51 import javax.persistence.Column;
52 import javax.persistence.Entity;
53 import javax.persistence.FetchType;
54 import javax.persistence.GeneratedValue;
55 import javax.persistence.GenerationType;
56 import javax.persistence.Id;
57 import javax.persistence.Index;
58 import javax.persistence.Inheritance;
59 import javax.persistence.InheritanceType;
60 import javax.persistence.JoinColumn;
61 import javax.persistence.ManyToOne;
62 import javax.persistence.OneToMany;
63 import javax.persistence.SequenceGenerator;
64 import javax.persistence.Table;
65 import javax.validation.constraints.Digits;
66 import lombok.AllArgsConstructor;
67 import lombok.Getter;
68 import lombok.NoArgsConstructor;
69 import lombok.Setter;
70 import org.onap.portal.domain.db.fn.FnUser;
71 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
72
73 @Table(name = "domain")
74 @Getter
75 @Setter
76 @Entity
77 @NoArgsConstructor
78 @AllArgsConstructor
79 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
80 public class DomainVo implements Serializable, Cloneable, Comparable {
81
82   private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DomainVo.class);
83   private static final long serialVersionUID = 1L;
84
85   @Id
86   @GeneratedValue(strategy = GenerationType.AUTO)
87   @Column(name = "id", length = 11, nullable = false, columnDefinition = "bigint AUTO_INCREMENT")
88   @Digits(integer = 11, fraction = 0)
89   private Long id;
90   private LocalDateTime created;
91   private LocalDateTime modified;
92   private Long rowNum;
93   private Serializable auditUserId;
94
95   @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
96   @JoinColumn(name = "created_id", columnDefinition = "bigint")
97   private DomainVo createdId;
98   @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
99   @JoinColumn(name = "modified_id", columnDefinition = "bigint")
100   private DomainVo modifiedId;
101
102   @OneToMany(
103       targetEntity = DomainVo.class,
104       mappedBy = "createdId",
105       cascade = CascadeType.MERGE,
106       fetch = FetchType.LAZY
107   )
108   private Set<DomainVo> fnUsersCreatedId;
109   @OneToMany(
110       targetEntity = DomainVo.class,
111       mappedBy = "modifiedId",
112       cascade = CascadeType.MERGE,
113       fetch = FetchType.LAZY
114   )
115   private Set<DomainVo> fnUsersModifiedId;
116
117   public DomainVo(Long id) {
118     this.id = id;
119   }
120
121   @Override
122   public int compareTo(Object obj) {
123     Long c1 = this.getId();
124     Long c2 = ((org.onap.portalsdk.core.domain.support.DomainVo) obj).getId();
125     return c1 != null && c2 != null ? c1.compareTo(c2) : 1;
126   }
127
128   public Object copy(boolean isIdNull) {
129     ByteArrayOutputStream baos = null;
130     ByteArrayInputStream bais = null;
131     ObjectOutputStream oos = null;
132     ObjectInputStream ois = null;
133     DomainVo newVo = null;
134
135     try {
136       baos = new ByteArrayOutputStream();
137       oos = new ObjectOutputStream(baos);
138       oos.writeObject(this);
139       bais = new ByteArrayInputStream(baos.toByteArray());
140       ois = new ObjectInputStream(bais);
141       newVo = (DomainVo) ois.readObject();
142       if (isIdNull) {
143         newVo.setId(null);
144       }
145     } catch (Exception var8) {
146       logger.error("exception occured", var8);
147     }
148
149     return newVo;
150   }
151
152   public Object clone() throws CloneNotSupportedException {
153     return super.clone();
154   }
155
156   public boolean equals(Object other) {
157     if (this == other) {
158       return true;
159     } else if (other == null) {
160       return false;
161     } else if (!(other instanceof DomainVo)) {
162       return false;
163     } else {
164       DomainVo castOther = (DomainVo) other;
165       return this.getId().equals(castOther.getId())
166           && this.getCreated().equals(castOther.getCreated())
167           && this.getModified().equals(castOther.getModified());
168     }
169   }
170
171   public DomainVo(DomainVo domainVo) {
172     this.id = domainVo.id;
173     this.created = domainVo.created;
174     this.modified = domainVo.modified;
175     this.rowNum = domainVo.rowNum;
176     this.auditUserId = domainVo.auditUserId;
177   }
178 }