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.service;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.google.gson.JsonObject;
29 import com.google.gson.annotations.Expose;
31 import java.io.Serializable;
33 import javax.persistence.Column;
34 import javax.persistence.Entity;
35 import javax.persistence.Id;
36 import javax.persistence.Table;
37 import javax.persistence.Transient;
39 import org.hibernate.annotations.Type;
40 import org.hibernate.annotations.TypeDef;
41 import org.hibernate.annotations.TypeDefs;
42 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
46 @Table(name = "services")
47 @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
48 public class Service implements Serializable {
51 * The serial version id.
53 private static final long serialVersionUID = 1331119060272760758L;
56 private static final EELFLogger logger = EELFManager.getInstance().getLogger(Service.class);
59 @Column(name = "service_uuid", unique = true)
60 private String serviceUuid;
62 @Column(nullable = false, name = "name")
65 @Column(name = "version")
66 private String version;
70 @Column(columnDefinition = "json", name = "service_details")
71 private JsonObject serviceDetails;
75 @Column(columnDefinition = "json", name = "resource_details")
76 private JsonObject resourceDetails;
87 public Service(JsonObject serviceDetails, JsonObject resourceDetails, String version) {
88 this.name = serviceDetails.get("name").getAsString();
89 this.serviceUuid = serviceDetails.get("UUID").getAsString();
90 this.serviceDetails = serviceDetails;
91 this.resourceDetails = resourceDetails;
92 this.version = version;
95 public String getServiceUuid() {
99 public JsonObject getServiceDetails() {
100 return serviceDetails;
103 public JsonObject getResourceDetails() {
104 return resourceDetails;
107 public JsonObject getResourceByType(String type) {
108 return (JsonObject) resourceDetails.get(type);
112 public int hashCode() {
113 final int prime = 31;
115 result = prime * result + ((serviceUuid == null) ? 0 : serviceUuid.hashCode());
120 public boolean equals(Object obj) {
127 if (getClass() != obj.getClass()) {
130 Service other = (Service) obj;
131 if (serviceUuid == null) {
132 if (other.serviceUuid != null) {
135 } else if (!serviceUuid.equals(other.serviceUuid)) {