001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.ksb.impl.registry;
017
018import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
019import org.kuali.rice.ksb.api.registry.ServiceEndpointStatus;
020import org.kuali.rice.ksb.api.registry.ServiceInfo;
021import org.kuali.rice.ksb.api.registry.ServiceInfoContract;
022
023import javax.persistence.Column;
024import javax.persistence.Entity;
025import javax.persistence.GeneratedValue;
026import javax.persistence.Id;
027import javax.persistence.Table;
028import javax.xml.namespace.QName;
029import java.io.Serializable;
030
031/**
032 * Model bean that represents the definition of a service on the bus.
033 * 
034 * @see ServiceInfo
035 *
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 */
038
039@Entity
040@Table(name="KRSB_SVC_DEF_T")
041public class ServiceInfoBo implements ServiceInfoContract, Serializable {
042 
043        private static final long serialVersionUID = -4244884858494208070L;
044
045    @Id
046    @GeneratedValue(generator = "KRSB_SVC_DEF_S")
047    @PortableSequenceGenerator(name = "KRSB_SVC_DEF_S")
048        @Column(name = "SVC_DEF_ID")
049        private String serviceId;
050        
051        @Column(name = "SVC_NM")
052        private String serviceName;
053    
054        @Column(name = "SVC_URL", length = 500)
055        private String endpointUrl;
056        
057        @Column(name = "INSTN_ID")
058        private String instanceId;
059
060        @Column(name = "APPL_ID")
061        private String applicationId;
062
063        @Column(name = "SRVR_IP")
064        private String serverIpAddress;
065        
066        @Column(name = "TYP_CD")
067        private String type;
068        
069        @Column(name = "SVC_VER")
070        private String serviceVersion;
071        
072        @Column(name = "STAT_CD")
073        private String statusCode;
074        
075        @Column(name = "SVC_DSCRPTR_ID")
076        private String serviceDescriptorId;
077        
078        @Column(name = "CHKSM", length = 30)
079        private String checksum;
080
081    @Deprecated
082        @Column(name = "VER_NBR")
083        private Long versionNumber;
084
085    public ServiceInfoBo() {
086        this.versionNumber = Long.valueOf(1);
087    }
088
089    public String getServiceId() {
090        return serviceId;
091    }
092
093    public void setServiceId(String serviceId) {
094        this.serviceId = serviceId;
095    }
096
097    @Override
098    public QName getServiceName() {
099        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}