View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ksb.impl.registry;
17  
18  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
19  import org.kuali.rice.ksb.api.registry.ServiceEndpointStatus;
20  import org.kuali.rice.ksb.api.registry.ServiceInfo;
21  import org.kuali.rice.ksb.api.registry.ServiceInfoContract;
22  
23  import javax.persistence.Column;
24  import javax.persistence.Entity;
25  import javax.persistence.GeneratedValue;
26  import javax.persistence.Id;
27  import javax.persistence.Table;
28  import javax.xml.namespace.QName;
29  import java.io.Serializable;
30  
31  /**
32   * Model bean that represents the definition of a service on the bus.
33   * 
34   * @see ServiceInfo
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  
39  @Entity
40  @Table(name="KRSB_SVC_DEF_T")
41  public class ServiceInfoBo implements ServiceInfoContract, Serializable {
42   
43  	private static final long serialVersionUID = -4244884858494208070L;
44  
45      @Id
46      @GeneratedValue(generator = "KRSB_SVC_DEF_S")
47      @PortableSequenceGenerator(name = "KRSB_SVC_DEF_S")
48  	@Column(name = "SVC_DEF_ID")
49  	private String serviceId;
50  	
51  	@Column(name = "SVC_NM")
52  	private String serviceName;
53      
54  	@Column(name = "SVC_URL", length = 500)
55  	private String endpointUrl;
56  	
57  	@Column(name = "INSTN_ID")
58  	private String instanceId;
59  
60  	@Column(name = "APPL_ID")
61  	private String applicationId;
62  
63  	@Column(name = "SRVR_IP")
64  	private String serverIpAddress;
65  	
66  	@Column(name = "TYP_CD")
67  	private String type;
68  	
69  	@Column(name = "SVC_VER")
70  	private String serviceVersion;
71  	
72  	@Column(name = "STAT_CD")
73  	private String statusCode;
74  	
75  	@Column(name = "SVC_DSCRPTR_ID")
76  	private String serviceDescriptorId;
77  	
78  	@Column(name = "CHKSM", length = 30)
79  	private String checksum;
80  
81      @Deprecated
82  	@Column(name = "VER_NBR")
83  	private Long versionNumber;
84  
85      public ServiceInfoBo() {
86          this.versionNumber = Long.valueOf(1);
87      }
88  
89      public String getServiceId() {
90          return serviceId;
91      }
92  
93      public void setServiceId(String serviceId) {
94          this.serviceId = serviceId;
95      }
96  
97      @Override
98      public QName getServiceName() {
99          if (this.serviceName == null) {
100             return null;
101         }
102         return QName.valueOf(this.serviceName);
103     }
104 
105     public void setServiceName(String serviceName) {
106         this.serviceName = serviceName;
107     }
108 
109     public String getEndpointUrl() {
110         return endpointUrl;
111     }
112 
113     public void setEndpointUrl(String endpointUrl) {
114         this.endpointUrl = endpointUrl;
115     }
116 
117     public String getInstanceId() {
118         return instanceId;
119     }
120 
121     public void setInstanceId(String instanceId) {
122         this.instanceId = instanceId;
123     }
124 
125     public String getApplicationId() {
126         return applicationId;
127     }
128 
129     public void setApplicationId(String applicationId) {
130         this.applicationId = applicationId;
131     }
132 
133     public String getServerIpAddress() {
134         return serverIpAddress;
135     }
136 
137     public void setServerIpAddress(String serverIpAddress) {
138         this.serverIpAddress = serverIpAddress;
139     }
140 
141     public String getType() {
142         return type;
143     }
144 
145     public void setType(String type) {
146         this.type = type;
147     }
148 
149     public String getServiceVersion() {
150         return serviceVersion;
151     }
152 
153     public void setServiceVersion(String serviceVersion) {
154         this.serviceVersion = serviceVersion;
155     }
156 
157     public String getStatusCode() {
158         return statusCode;
159     }
160 
161     public void setStatusCode(String statusCode) {
162         this.statusCode = statusCode;
163     }
164 
165     public String getServiceDescriptorId() {
166         return serviceDescriptorId;
167     }
168 
169     public void setServiceDescriptorId(String serviceDescriptorId) {
170         this.serviceDescriptorId = serviceDescriptorId;
171     }
172 
173     public String getChecksum() {
174         return checksum;
175     }
176 
177     public void setChecksum(String checksum) {
178         this.checksum = checksum;
179     }
180 
181     public Long getVersionNumber() {
182         return versionNumber;
183     }
184 
185     /**
186      * Version number is deprecated, so this method does nothing.
187      *
188      * @deprecated version number is no longer used
189      */
190     @Deprecated
191     public void setVersionNumber(Long versionNumber) {
192         // no longer does anything
193     }
194 
195     @Override
196 	public ServiceEndpointStatus getStatus() {
197 		if (getStatusCode() == null) {
198 			return null;
199 		}
200 		return ServiceEndpointStatus.fromCode(getStatusCode());
201 	}
202 
203 	public static ServiceInfo to(ServiceInfoBo bo) {
204 		if (bo == null) {
205 			return null;
206 		}
207 		return ServiceInfo.Builder.create(bo).build();
208 	}
209 	
210 	public static ServiceInfoBo from(ServiceInfo im) {
211 		if (im == null) {
212 			return null;
213 		}
214 		ServiceInfoBo bo = new ServiceInfoBo();
215 		bo.serviceId = im.getServiceId();
216 		bo.serviceName = im.getServiceName().toString();
217 		bo.endpointUrl = im.getEndpointUrl();
218 		bo.instanceId = im.getInstanceId();
219 		bo.applicationId = im.getApplicationId();
220 		bo.serverIpAddress = im.getServerIpAddress();
221 		bo.type = im.getType();
222 		bo.serviceVersion = im.getServiceVersion();
223 		bo.statusCode = im.getStatus().getCode();
224 		bo.serviceDescriptorId = im.getServiceDescriptorId();
225 		bo.checksum = im.getChecksum();
226 		bo.versionNumber = im.getVersionNumber();
227 		return bo;
228 	}
229 	
230 	
231 	
232 	
233 }