001/**
002 * Copyright 2005-2015 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.kim.bo.ui;
017
018import javax.persistence.CascadeType;
019import javax.persistence.Column;
020import javax.persistence.Entity;
021import javax.persistence.GeneratedValue;
022import javax.persistence.Id;
023import javax.persistence.JoinColumn;
024import javax.persistence.ManyToOne;
025import javax.persistence.Table;
026
027import org.apache.commons.lang.StringUtils;
028import org.eclipse.persistence.annotations.JoinFetch;
029import org.eclipse.persistence.annotations.JoinFetchType;
030import org.kuali.rice.kim.impl.identity.phone.EntityPhoneTypeBo;
031import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
032
033/**
034 * This is a description of what this class does - shyu don't forget to fill this in. 
035 * 
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 *
038 */
039@Entity
040@Table(name = "KRIM_PND_PHONE_MT")
041public class PersonDocumentPhone extends PersonDocumentBoDefaultBase {
042    private static final long serialVersionUID = 1L;
043
044    @PortableSequenceGenerator(name = "KRIM_ENTITY_PHONE_ID_S")
045    @GeneratedValue(generator = "KRIM_ENTITY_PHONE_ID_S")
046    @Id
047    @Column(name = "ENTITY_PHONE_ID")
048    protected String entityPhoneId;
049
050    @Column(name = "ENT_TYP_CD")
051    protected String entityTypeCode;
052
053    @Column(name = "PHONE_TYP_CD")
054    protected String phoneTypeCode;
055
056    @Column(name = "PHONE_NBR")
057    protected String phoneNumber;
058
059    @Column(name = "PHONE_EXTN_NBR")
060    protected String extensionNumber;
061
062    @Column(name = "POSTAL_CNTRY_CD")
063    protected String countryCode;
064
065    @JoinFetch(value= JoinFetchType.OUTER)
066    @ManyToOne(targetEntity = EntityPhoneTypeBo.class, cascade = { CascadeType.REFRESH })
067    @JoinColumn(name = "PHONE_TYP_CD", referencedColumnName = "PHONE_TYP_CD", insertable = false, updatable = false)
068    protected EntityPhoneTypeBo phoneType;
069
070    // Waiting until we pull in from KFS                       
071    // protected Country country;                       
072    public PersonDocumentPhone() {
073        this.active = true;
074    }
075
076    /**
077         * @see org.kuali.rice.kim.bo.entity.KimEntityPhone#getCountryCode()
078         */
079    public String getCountryCode() {
080        return countryCode;
081    }
082
083    /**
084         * @see org.kuali.rice.kim.bo.entity.KimEntityPhone#getEntityPhoneId()
085         */
086    public String getEntityPhoneId() {
087        return entityPhoneId;
088    }
089
090    /**
091         * @see org.kuali.rice.kim.bo.entity.KimEntityPhone#getExtensionNumber()
092         */
093    public String getExtensionNumber() {
094        return extensionNumber;
095    }
096
097    /**
098         * @see org.kuali.rice.kim.bo.entity.KimEntityPhone#getPhoneNumber()
099         */
100    public String getPhoneNumber() {
101        return phoneNumber;
102    }
103
104    /**
105         * @see org.kuali.rice.kim.bo.entity.KimEntityPhone#getPhoneTypeCode()
106         */
107    public String getPhoneTypeCode() {
108        return phoneTypeCode;
109    }
110
111    /**
112         * @see org.kuali.rice.kim.bo.entity.KimEntityPhone#setCountryCode(java.lang.String)
113         */
114    public void setCountryCode(String countryCode) {
115        this.countryCode = countryCode;
116    }
117
118    /**
119         * @see org.kuali.rice.kim.bo.entity.KimEntityPhone#setExtensionNumber(java.lang.String)
120         */
121    public void setExtensionNumber(String extensionNumber) {
122        this.extensionNumber = extensionNumber;
123    }
124
125    /**
126         * @see org.kuali.rice.kim.bo.entity.KimEntityPhone#setPhoneNumber(java.lang.String)
127         */
128    public void setPhoneNumber(String phoneNumber) {
129        this.phoneNumber = phoneNumber;
130    }
131
132    /**
133         * @see org.kuali.rice.kim.bo.entity.KimEntityPhone#setPhoneTypeCode(java.lang.String)
134         */
135    public void setPhoneTypeCode(String phoneTypeCode) {
136        this.phoneTypeCode = phoneTypeCode;
137    }
138
139    /**
140         * @see org.kuali.rice.kim.bo.entity.KimDefaultableEntityTypeData#getEntityTypeCode()
141         */
142    public String getEntityTypeCode() {
143        return entityTypeCode;
144    }
145
146    /**
147         * @see org.kuali.rice.kim.bo.entity.KimDefaultableEntityTypeData#setEntityTypeCode(java.lang.String)
148         */
149    public void setEntityTypeCode(String entityTypeCode) {
150        this.entityTypeCode = entityTypeCode;
151    }
152
153    public EntityPhoneTypeBo getPhoneType() {
154        return this.phoneType;
155    }
156
157    public void setPhoneType(EntityPhoneTypeBo phoneType) {
158        this.phoneType = phoneType;
159    }
160
161    public void setEntityPhoneId(String entityPhoneId) {
162        this.entityPhoneId = entityPhoneId;
163    }
164
165    public String getFormattedPhoneNumber() {
166        StringBuilder sb = new StringBuilder(30);
167        // TODO: get extension from country code table                       
168        // TODO: append "+xxx" if country is not the default country                       
169        sb.append(getPhoneNumber());
170        if (StringUtils.isNotBlank(getExtensionNumber())) {
171            sb.append(" x");
172            sb.append(getExtensionNumber());
173        }
174        return sb.toString();
175    }
176}