/**
* TNTConcept Easy Enterprise Management by Autentia Real Bussiness Solution S.L.
* Copyright (C) 2007 Autentia Real Bussiness Solution S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.autentia.tnt.businessobject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.autentia.tnt.dao.ITransferObject;
import com.autentia.tnt.tracking.TrackingBase;
import com.autentia.tnt.tracking.annotation.ChangesHistory;
import com.autentia.tnt.tracking.mail.TrackChangesMailService;
/**
* Transfer object to store Contacts
*
* @author stajanov code generator
*/
public class Contact extends TrackingBase implements Serializable,
ITransferObject {
/** Serial version field */
private static final long serialVersionUID = -1L;
public Contact() {
}
/* contact - generated by stajanov (do not edit/delete) */
// Fields
private Integer id;
private String name;
private String email;
private String phone;
private String mobile;
private boolean notified;
private Integer ownerId;
private Integer departmentId;
private Date insertDate;
private Date updateDate;
private Set<ContactInfo> contactInfos = new HashSet<ContactInfo>(0);
private String email2;
private String phone2;
private String fax;
private String address;
private String postalCode;
private String city;
private String country;
private Province province;
private boolean active;
private Set<Tag> tags = new HashSet<Tag>(0);
private Set<User> owners = new HashSet<User>(0);
public Set<User> getOwners() {
return this.owners;
}
private void setOwners(Set<User> owners) {
this.owners = owners;
}
public boolean addOwner(User owner) {
addEntityChange(FIELD_OWNERS, "", owner.getName(), owner.getId()
.toString());
return this.owners.add(owner);
}
public boolean removeOwner(User owner) {
addEntityChange(FIELD_OWNERS, owner.getName(), "", owner.getId()
.toString());
return this.owners.remove(owner);
}
public Integer getId() {
return id;
}
private void setId(Integer id) {
this.id = id;
}
public Set<ContactInfo> getContactInfos() {
return this.contactInfos;
}
private void setContactInfos(Set<ContactInfo> contactInfos) {
this.contactInfos = contactInfos;
}
public boolean addContactInfo(ContactInfo contactInfo) {
addEntityChange(FIELD_POSITION, "", contactInfo.getPosition().getName(), contactInfo.getOrganization().getId()
.toString()+"_"+contactInfo.getDepartment().getId().toString()+"_"+contactInfo.getPosition().getId().toString());
return this.contactInfos.add(contactInfo);
}
public boolean removeContactInfo(ContactInfo contactInfo) {
addEntityChange(FIELD_POSITION, contactInfo.getPosition().getName(), "", contactInfo.getOrganization().getId()
.toString()+"_"+contactInfo.getDepartment().getId().toString()+"_"+contactInfo.getPosition().getId().toString());
return this.contactInfos.remove(contactInfo);
}
public String getEmail2() {
return email2;
}
@ChangesHistory (fieldName=FIELD_EMAIL2)
public void setEmail2(String email2) {
this.email2 = email2;
}
public String getPhone2() {
return phone2;
}
@ChangesHistory (fieldName=FIELD_PHONE2)
public void setPhone2(String phone2) {
this.phone2 = phone2;
}
public String getFax() {
return fax;
}
@ChangesHistory (fieldName=FIELD_FAX)
public void setFax(String fax) {
this.fax = fax;
}
public String getAddress() {
return address;
}
@ChangesHistory (fieldName=FIELD_ADDRESS)
public void setAddress(String address) {
this.address = address;
}
public String getPostalCode() {
return postalCode;
}
@ChangesHistory (fieldName=FIELD_POSTALCODE)
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getCity() {
return city;
}
@ChangesHistory (fieldName=FIELD_CITY)
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
@ChangesHistory (fieldName=FIELD_COUNTRY)
public void setCountry(String country) {
this.country = country;
}
public Province getProvince() {
return province;
}
@ChangesHistory (fieldName=FIELD_PROVINCE, method="getName")
public void setProvince(Province province) {
this.province = province;
}
public String getName() {
return name;
}
@ChangesHistory (fieldName=FIELD_NAME)
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
@ChangesHistory (fieldName=FIELD_EMAIL)
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
@ChangesHistory (fieldName=FIELD_PHONE)
public void setPhone(String phone) {
this.phone = phone;
}
public String getMobile() {
return mobile;
}
@ChangesHistory (fieldName=FIELD_MOBILE)
public void setMobile(String mobile) {
this.mobile = mobile;
}
public boolean isNotified() {
return notified;
}
@ChangesHistory (fieldName=FIELD_NOTIFIED)
public void setNotified(boolean notified) {
this.notified = notified;
}
public Integer getOwnerId() {
return ownerId;
}
public void setOwnerId(Integer ownerId) {
this.ownerId = ownerId;
}
public Integer getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Integer departmentId) {
this.departmentId = departmentId;
}
public Date getInsertDate() {
return insertDate;
}
public void setInsertDate(Date insertDate) {
this.insertDate = insertDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public Set<Tag> getTags() {
return this.tags;
}
private void setTags(Set<Tag> tags) {
this.tags = tags;
}
public boolean addTag(Tag tag) {
addEntityChange(FIELD_TAGS, "", tag.getName(), tag.getId()
.toString());
return this.tags.add(tag);
}
public boolean removeTag(Tag tag) {
addEntityChange(FIELD_TAGS, tag.getName(), "", tag.getId()
.toString());
return this.tags.remove(tag);
}
@Override
public boolean equals(Object that) {
try {
if (that == null)
return false;
else
return this.getId().equals(((Contact) that).getId());
} catch (Exception e) {
return false;
}
}
@Override
public int hashCode() {
if (this.getId() == null)
return super.hashCode();
else
return this.getId().intValue();
}
public List<Integer> getOwnersId() {
List<Integer> ownersId = new ArrayList();
if (this.getOwners() != null) {
for (User owner : this.getOwners()) {
ownersId.add(owner.getId());
}
}
return ownersId;
}
/*****************************************************************************************/
public static final String CHANGES_MAIL_KEY = "contact.mail.changes.textKey";
public static final String FIELD_NAME = "contact.name";
public static final String FIELD_EMAIL = "contact.email";
public static final String FIELD_EMAIL2 = "contact.email2";
public static final String FIELD_PHONE = "contact.phone";
public static final String FIELD_PHONE2 = "contact.phone2";
public static final String FIELD_MOBILE = "contact.mobile";
public static final String FIELD_FAX = "contact.fax";
public static final String FIELD_ADDRESS = "contact.address";
public static final String FIELD_POSTALCODE = "contact.postalCode";
public static final String FIELD_CITY = "contact.city";
public static final String FIELD_COUNTRY = "contact.country";
public static final String FIELD_PROVINCE = "contact.province";
public static final String FIELD_NOTIFIED = "contact.notified";
public static final String FIELD_TAGS = "contact.tags";
public static final String FIELD_POSITION = "contact.position";
public static final String FIELD_DEPARTMENT = "contact.department";
public static final String FIELD_ORGANIZATION = "contact.organization";
public static final String FIELD_OWNERS = "contact.owners";
}