]> git.mxchange.org Git - jcontacts-business-core.git/blobdiff - src/org/mxchange/jcontactsbusiness/CompanyContact.java
Sorted members
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / CompanyContact.java
index 2e472d0e9afcfccad87042b18c0307b41b01afc8..2319949cf9f19a6eddbecbcee6744c8fa81e0b0d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Roland Haeder
+ * Copyright (C) 2016 Roland Haeder
  *
  * 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
  */
 package org.mxchange.jcontactsbusiness;
 
+import java.util.Calendar;
 import java.util.List;
+import java.util.Objects;
+import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -24,17 +27,20 @@ import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
-import javax.persistence.OneToMany;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
 import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
 import org.mxchange.jcontactsbusiness.basicdata.CompanyBasicData;
 import org.mxchange.jcontactsbusiness.branch.BranchOffice;
-import org.mxchange.jcontactsbusiness.branch.CompanyBranchOffice;
 import org.mxchange.jcontactsbusiness.employee.CompanyEmployee;
 import org.mxchange.jcontactsbusiness.employee.Employee;
 import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadQuartersData;
 import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData;
+import org.mxchange.jusercore.model.user.LoginUser;
+import org.mxchange.jusercore.model.user.User;
 
 /**
  * A POJO for business contacts
@@ -58,11 +64,10 @@ public class CompanyContact implements BusinessContact, Comparable<BusinessConta
        private BusinessBasicData basicBusinessData;
 
        /**
-        * Reference to employee branches
+        * Reference to company branch offfices
         */
-       @JoinColumn (name = "company_branches_id", nullable = false, updatable = false)
-       @OneToMany (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.ALL)
-       private List<BranchOffice> branches;
+       @Transient
+       private List<BranchOffice> brancheOffices;
 
        /**
         * Reference to contact person
@@ -75,7 +80,7 @@ public class CompanyContact implements BusinessContact, Comparable<BusinessConta
         * Id number
         */
        @Id
-       @Column (name = "company_contact_id", length = 20, nullable = false, updatable = false)
+       @Column (name = "company_id", length = 20, nullable = false, updatable = false)
        @GeneratedValue (strategy = GenerationType.IDENTITY)
        private Long companyContactId;
 
@@ -87,11 +92,19 @@ public class CompanyContact implements BusinessContact, Comparable<BusinessConta
        private Employee companyFounder;
 
        /**
-        * Reference to employee list
+        * Timestamp when this entry has been created
         */
-       @JoinColumn (name = "company_employees_id", nullable = false, updatable = false)
-       @OneToMany (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
-       private List<Employee> employees;
+       @Basic (optional = false)
+       @Temporal (TemporalType.TIMESTAMP)
+       @Column (name = "company_entry_created", nullable = false, updatable = false)
+       private Calendar contactCreated;
+
+       /**
+        * User owner instance
+        */
+       @JoinColumn (name = "company_user_id", nullable = false, updatable = false)
+       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.MERGE, optional = false)
+       private User contactUserOwner;
 
        /**
         * Reference to headquarters data
@@ -105,6 +118,19 @@ public class CompanyContact implements BusinessContact, Comparable<BusinessConta
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
 
+       @Override
+       public boolean equals (final Object object) {
+               if (object == null) {
+                       return false;
+               } else if (getClass() != object.getClass()) {
+                       return false;
+               }
+
+               final BusinessContact other = (BusinessContact) object;
+
+               return Objects.equals(this.getBasicBusinessData(), other.getBasicBusinessData());
+       }
+
        @Override
        public BusinessBasicData getBasicBusinessData () {
                return this.basicBusinessData;
@@ -116,13 +142,13 @@ public class CompanyContact implements BusinessContact, Comparable<BusinessConta
        }
 
        @Override
-       public List<BranchOffice> getBranches () {
-               return this.branches;
+       public List<BranchOffice> getBrancheOffices () {
+               return this.brancheOffices;
        }
 
        @Override
-       public void setBranches (final List<BranchOffice> branches) {
-               this.branches = branches;
+       public void setBrancheOffices (final List<BranchOffice> brancheOffices) {
+               this.brancheOffices = brancheOffices;
        }
 
        @Override
@@ -156,13 +182,23 @@ public class CompanyContact implements BusinessContact, Comparable<BusinessConta
        }
 
        @Override
-       public List<Employee> getEmployees () {
-               return this.employees;
+       public Calendar getContactCreated () {
+               return this.contactCreated;
        }
 
        @Override
-       public void setEmployees (final List<Employee> employees) {
-               this.employees = employees;
+       public void setContactCreated (final Calendar contactCreated) {
+               this.contactCreated = contactCreated;
+       }
+
+       @Override
+       public User getContactUserOwner () {
+               return this.contactUserOwner;
+       }
+
+       @Override
+       public void setContactUserOwner (final User contactUserOwner) {
+               this.contactUserOwner = contactUserOwner;
        }
 
        @Override
@@ -174,4 +210,11 @@ public class CompanyContact implements BusinessContact, Comparable<BusinessConta
        public void setHeadQuartersData (final HeadQuartersData headQuartersData) {
                this.headQuartersData = headQuartersData;
        }
+
+       @Override
+       public int hashCode () {
+               int hash = 3;
+               hash = 37 * hash + Objects.hashCode(this.getBasicBusinessData());
+               return hash;
+       }
 }