From de43644d8e7c57c53a3c083ad28db96a4a9fe567 Mon Sep 17 00:00:00 2001 From: mairess Date: Fri, 28 Jun 2024 16:38:27 -0300 Subject: [PATCH] feat: add entities --- .../java/com/maires/wnet/entity/Address.java | 168 ++++++++++++++ .../java/com/maires/wnet/entity/Customer.java | 187 ++++++++++++++++ .../com/maires/wnet/entity/Equipment.java | 168 ++++++++++++++ .../com/maires/wnet/entity/Installation.java | 206 ++++++++++++++++++ .../java/com/maires/wnet/entity/Plan.java | 164 ++++++++++++++ .../com/maires/wnet/entity/RuralAddress.java | 74 +++++++ .../com/maires/wnet/entity/Technician.java | 122 +++++++++++ .../com/maires/wnet/entity/UrbanAddress.java | 119 ++++++++++ 8 files changed, 1208 insertions(+) create mode 100644 src/main/java/com/maires/wnet/entity/Address.java create mode 100644 src/main/java/com/maires/wnet/entity/Customer.java create mode 100644 src/main/java/com/maires/wnet/entity/Equipment.java create mode 100644 src/main/java/com/maires/wnet/entity/Installation.java create mode 100644 src/main/java/com/maires/wnet/entity/Plan.java create mode 100644 src/main/java/com/maires/wnet/entity/RuralAddress.java create mode 100644 src/main/java/com/maires/wnet/entity/Technician.java create mode 100644 src/main/java/com/maires/wnet/entity/UrbanAddress.java diff --git a/src/main/java/com/maires/wnet/entity/Address.java b/src/main/java/com/maires/wnet/entity/Address.java new file mode 100644 index 0000000..856632b --- /dev/null +++ b/src/main/java/com/maires/wnet/entity/Address.java @@ -0,0 +1,168 @@ +package com.maires.wnet.entity; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.DiscriminatorColumn; +import jakarta.persistence.DiscriminatorType; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Inheritance; +import jakarta.persistence.InheritanceType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; + +/** + * The type Address. + */ +@Entity(name = "addresses") +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "address_type", + discriminatorType = DiscriminatorType.STRING) +public class Address { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String city; + + private String state; + + private String zipCode; + + @ManyToOne + @JoinColumn(name = "customer_id") + private Customer customer; + + @OneToOne(mappedBy = "address", cascade = CascadeType.ALL) + private Installation installation; + + /** + * Instantiates a new Address. + */ + public Address() { + } + + /** + * Instantiates a new Address. + * + * @param city the city + * @param state the state + * @param zipCode the zipCode + */ + public Address(String city, String state, String zipCode) { + this.city = city; + this.state = state; + this.zipCode = zipCode; + } + + /** + * Gets id. + * + * @return the id + */ + public Long getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Gets installation. + * + * @return the installation + */ + public Installation getInstallation() { + return installation; + } + + /** + * Sets installation. + * + * @param installation the installation + */ + public void setInstallation(Installation installation) { + this.installation = installation; + } + + /** + * Gets customer. + * + * @return the customer + */ + public Customer getCustomer() { + return customer; + } + + /** + * Sets customer. + * + * @param customer the customer + */ + public void setCustomer(Customer customer) { + this.customer = customer; + } + + /** + * Gets city. + * + * @return the city + */ + public String getCity() { + return city; + } + + /** + * Sets city. + * + * @param city the city + */ + public void setCity(String city) { + this.city = city; + } + + /** + * Gets state. + * + * @return the state + */ + public String getState() { + return state; + } + + /** + * Sets state. + * + * @param state the state + */ + public void setState(String state) { + this.state = state; + } + + /** + * Gets zipCode. + * + * @return the zipCode + */ + public String getZipCode() { + return zipCode; + } + + /** + * Sets zipCode. + * + * @param zipCode the zipCode + */ + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/entity/Customer.java b/src/main/java/com/maires/wnet/entity/Customer.java new file mode 100644 index 0000000..5a73020 --- /dev/null +++ b/src/main/java/com/maires/wnet/entity/Customer.java @@ -0,0 +1,187 @@ +package com.maires.wnet.entity; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; + + +/** + * The type Customer. + */ +@Entity +@Table(name = "customers") +public class Customer { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + private String cpf; + private String phone; + + @Column(unique = true) + private String email; + + private String registrationDate; + + @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL) + private List
addresses; + + /** + * Instantiates a new Customer. + */ + public Customer() { + } + + /** + * Instantiates a new Customer. + * + * @param name the name + * @param cpf the cpf + * @param phone the phone + * @param email the email + */ + public Customer(String name, String cpf, String phone, String email) { + this.name = name; + this.cpf = cpf; + this.phone = phone; + this.email = email; + LocalDateTime now = LocalDateTime.now().minusHours(3); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy'T'HH:mm:ss"); + this.registrationDate = now.format(formatter); + } + + /** + * Gets id. + * + * @return the id + */ + public Long getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Gets name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Sets name. + * + * @param name the name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets cpf. + * + * @return the cpf + */ + public String getCpf() { + return cpf; + } + + /** + * Sets cpf. + * + * @param cpf the cpf + */ + public void setCpf(String cpf) { + this.cpf = cpf; + } + + /** + * Gets phone. + * + * @return the phone + */ + public String getPhone() { + return phone; + } + + /** + * Sets phone. + * + * @param phone the phone + */ + public void setPhone(String phone) { + this.phone = phone; + } + + /** + * Gets email. + * + * @return the email + */ + public String getEmail() { + return email; + } + + /** + * Sets email. + * + * @param email the email + */ + public void setEmail(String email) { + this.email = email; + } + + /** + * Gets registration date. + * + * @return the registration date + */ + public String getRegistrationDate() { + return registrationDate; + } + + /** + * Sets registration date. + * + * @param registrationDate the registration date + */ + public void setRegistrationDate(String registrationDate) { + this.registrationDate = registrationDate; + } + + /** + * Gets addresses. + * + * @return the addresses + */ + public List
getAddresses() { + return addresses; + } + + /** + * Sets addresses. + * + * @param addresses the addresses + */ + public void setAddresses(List
addresses) { + this.addresses = addresses; + } +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/entity/Equipment.java b/src/main/java/com/maires/wnet/entity/Equipment.java new file mode 100644 index 0000000..f6f7d61 --- /dev/null +++ b/src/main/java/com/maires/wnet/entity/Equipment.java @@ -0,0 +1,168 @@ +package com.maires.wnet.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; +import java.util.Date; + +/** + * The type Equipment. + */ +@Entity +@Table(name = "equipments") +public class Equipment { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + + private Long id; + + private String type; + + private String model; + + private String serialNumber; + + private String manufacturer; + + private Date provisionDate; + + @OneToOne + private Installation installationFirst; + + @OneToOne + private Installation installationSecond; + + /** + * Instantiates a new Equipment. + */ + public Equipment() { + } + + /** + * Instantiates a new Equipment. + * + * @param type the addressType + * @param model the model + * @param serialNumber the serial number + * @param manufacturer the manufacturer + */ + public Equipment(String type, String model, String serialNumber, String manufacturer) { + this.type = type; + this.model = model; + this.serialNumber = serialNumber; + this.manufacturer = manufacturer; + this.provisionDate = new Date(); + } + + /** + * Gets id. + * + * @return the id + */ + public Long getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Gets addressType. + * + * @return the addressType + */ + public String getType() { + return type; + } + + /** + * Sets addressType. + * + * @param type the addressType + */ + public void setType(String type) { + this.type = type; + } + + /** + * Gets model. + * + * @return the model + */ + public String getModel() { + return model; + } + + /** + * Sets model. + * + * @param model the model + */ + public void setModel(String model) { + this.model = model; + } + + /** + * Gets serial number. + * + * @return the serial number + */ + public String getSerialNumber() { + return serialNumber; + } + + /** + * Sets serial number. + * + * @param serialNumber the serial number + */ + public void setSerialNumber(String serialNumber) { + this.serialNumber = serialNumber; + } + + /** + * Gets manufacturer. + * + * @return the manufacturer + */ + public String getManufacturer() { + return manufacturer; + } + + /** + * Sets manufacturer. + * + * @param manufacturer the manufacturer + */ + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } + + /** + * Gets provision date. + * + * @return the provision date + */ + public Date getProvisionDate() { + return provisionDate; + } + + /** + * Sets provision date. + * + * @param provisionDate the provision date + */ + public void setProvisionDate(Date provisionDate) { + this.provisionDate = provisionDate; + } +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/entity/Installation.java b/src/main/java/com/maires/wnet/entity/Installation.java new file mode 100644 index 0000000..cd4b611 --- /dev/null +++ b/src/main/java/com/maires/wnet/entity/Installation.java @@ -0,0 +1,206 @@ +package com.maires.wnet.entity; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; +import java.util.Date; + +/** + * The type Installation. + */ +@Entity +@Table(name = "installations") +public class Installation { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToOne + @JoinColumn(name = "address_id") + private Address address; + + @OneToOne(mappedBy = "installationFirst", cascade = CascadeType.ALL) + private Equipment equipmentFirst; + + @OneToOne(mappedBy = "installationSecond", cascade = CascadeType.ALL) + private Equipment equipmentSecond; + + @OneToOne + @JoinColumn(name = "plan_id") + private Plan plan; + + @OneToOne(mappedBy = "installation", cascade = CascadeType.ALL) + private Technician technician; + + private Date installationDate; + + /** + * Instantiates a new Installation. + */ + public Installation() { + } + + /** + * Instantiates a new Installation. + * + * @param address the address id + * @param plan the plan id + * @param technician the technician id + */ + public Installation(Address address, Plan plan, Technician technician) { + this.address = address; + this.plan = plan; + this.technician = technician; + this.installationDate = new Date(); + } + + /** + * Gets id. + * + * @return the id + */ + public Long getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Gets address id. + * + * @return the address id + */ + public Address getAddress() { + return address; + } + + /** + * Sets address id. + * + * @param address the address id + */ + public void setAddress(Address address) { + this.address = address; + } + + /** + * Gets equipment first. + * + * @return the equipment first + */ + public Equipment getEquipmentFirst() { + return equipmentFirst; + } + + /** + * Sets equipment first. + * + * @param equipmentFirst the equipment first + */ + public void setEquipmentFirst(Equipment equipmentFirst) { + this.equipmentFirst = equipmentFirst; + } + + /** + * Gets equipment second. + * + * @return the equipment second + */ + public Equipment getEquipmentSecond() { + return equipmentSecond; + } + + /** + * Sets equipment second. + * + * @param equipmentSecond the equipment second + */ + public void setEquipmentSecond(Equipment equipmentSecond) { + this.equipmentSecond = equipmentSecond; + } + + /** + * Gets plan. + * + * @return the plan + */ + public Plan getPlan() { + return plan; + } + + /** + * Sets plan. + * + * @param plan the plan + */ + public void setPlan(Plan plan) { + this.plan = plan; + } + + /** + * Gets plan id. + * + * @return the plan id + */ + public Plan getPlanId() { + return plan; + } + + /** + * Sets plan id. + * + * @param plan the plan id + */ + public void setPlanId(Plan plan) { + this.plan = plan; + } + + /** + * Gets technician id. + * + * @return the technician id + */ + public Technician getTechnician() { + return technician; + } + + /** + * Sets technician id. + * + * @param technician the technician id + */ + public void setTechnician(Technician technician) { + this.technician = technician; + } + + /** + * Gets installation date. + * + * @return the installation date + */ + public Date getInstallationDate() { + return installationDate; + } + + /** + * Sets installation date. + * + * @param installationDate the installation date + */ + public void setInstallationDate(Date installationDate) { + this.installationDate = installationDate; + } +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/entity/Plan.java b/src/main/java/com/maires/wnet/entity/Plan.java new file mode 100644 index 0000000..e566ed5 --- /dev/null +++ b/src/main/java/com/maires/wnet/entity/Plan.java @@ -0,0 +1,164 @@ +package com.maires.wnet.entity; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; + +/** + * The type Plan. + */ +@Entity +@Table(name = "plans") +public class Plan { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + + private Integer speed; + + private Double price; + + private boolean isActive; + + @OneToOne(mappedBy = "plan", cascade = CascadeType.ALL) + private Installation installation; + + /** + * Instantiates a new Plan. + */ + public Plan() { + } + + /** + * Instantiates a new Plan. + * + * @param name the name + * @param speed the speed + * @param price the price + * @param isActive the is active + * @param installation the installation + */ + public Plan(String name, Integer speed, Double price, boolean isActive, + Installation installation) { + this.name = name; + this.speed = speed; + this.price = price; + this.isActive = isActive; + this.installation = installation; + } + + /** + * Gets id. + * + * @return the id + */ + public Long getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Gets name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Sets name. + * + * @param name the name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets speed. + * + * @return the speed + */ + public Integer getSpeed() { + return speed; + } + + /** + * Sets speed. + * + * @param speed the speed + */ + public void setSpeed(Integer speed) { + this.speed = speed; + } + + /** + * Gets price. + * + * @return the price + */ + public Double getPrice() { + return price; + } + + /** + * Sets price. + * + * @param price the price + */ + public void setPrice(Double price) { + this.price = price; + } + + /** + * Is active boolean. + * + * @return the boolean + */ + public boolean isActive() { + return isActive; + } + + /** + * Sets active. + * + * @param active the active + */ + public void setActive(boolean active) { + isActive = active; + } + + /** + * Gets installation. + * + * @return the installation + */ + public Installation getInstallation() { + return installation; + } + + /** + * Sets installation. + * + * @param installation the installation + */ + public void setInstallation(Installation installation) { + this.installation = installation; + } +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/entity/RuralAddress.java b/src/main/java/com/maires/wnet/entity/RuralAddress.java new file mode 100644 index 0000000..767e68b --- /dev/null +++ b/src/main/java/com/maires/wnet/entity/RuralAddress.java @@ -0,0 +1,74 @@ +package com.maires.wnet.entity; + +import jakarta.persistence.DiscriminatorValue; +import jakarta.persistence.Entity; + +/** + * The type Rural address. + */ +@Entity +@DiscriminatorValue("rural") +public class RuralAddress extends Address { + + private String farmName; + + private String village; + + /** + * Instantiates a new Rural address. + */ + public RuralAddress() { + super(); + } + + /** + * Instantiates a new Rural address. + * + * @param city the city + * @param state the state + * @param zipCode the zip code + * @param farmName the farm name + * @param village the village + */ + public RuralAddress(String city, String state, String zipCode, String farmName, String village) { + super(city, state, zipCode); + this.farmName = farmName; + this.village = village; + } + + /** + * Gets farm name. + * + * @return the farm name + */ + public String getFarmName() { + return farmName; + } + + /** + * Sets farm name. + * + * @param farmName the farm name + */ + public void setFarmName(String farmName) { + this.farmName = farmName; + } + + /** + * Gets village. + * + * @return the village + */ + public String getVillage() { + return village; + } + + /** + * Sets village. + * + * @param village the village + */ + public void setVillage(String village) { + this.village = village; + } +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/entity/Technician.java b/src/main/java/com/maires/wnet/entity/Technician.java new file mode 100644 index 0000000..644660c --- /dev/null +++ b/src/main/java/com/maires/wnet/entity/Technician.java @@ -0,0 +1,122 @@ +package com.maires.wnet.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; + +/** + * The type Technician. + */ +@Entity +@Table(name = "technicians") +public class Technician { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + + private String phone; + + private String email; + + @OneToOne + @JoinColumn(name = "installation_id") + private Installation installation; + + /** + * Instantiates a new Technician. + */ + public Technician() { + } + + /** + * Instantiates a new Technician. + * + * @param name the name + * @param phone the phone + * @param email the email + */ + public Technician(String name, String phone, String email) { + this.name = name; + this.phone = phone; + this.email = email; + } + + /** + * Gets id. + * + * @return the id + */ + public Long getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Gets name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Sets name. + * + * @param name the name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets phone. + * + * @return the phone + */ + public String getPhone() { + return phone; + } + + /** + * Sets phone. + * + * @param phone the phone + */ + public void setPhone(String phone) { + this.phone = phone; + } + + /** + * Gets email. + * + * @return the email + */ + public String getEmail() { + return email; + } + + /** + * Sets email. + * + * @param email the email + */ + public void setEmail(String email) { + this.email = email; + } +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/entity/UrbanAddress.java b/src/main/java/com/maires/wnet/entity/UrbanAddress.java new file mode 100644 index 0000000..c08770d --- /dev/null +++ b/src/main/java/com/maires/wnet/entity/UrbanAddress.java @@ -0,0 +1,119 @@ +package com.maires.wnet.entity; + +import jakarta.persistence.DiscriminatorValue; +import jakarta.persistence.Entity; + +/** + * The type Urban address. + */ +@Entity +@DiscriminatorValue("urban") +public class UrbanAddress extends Address { + + private String street; + + private Integer streetNumber; + + private String complement; + + private String neighborhood; + + /** + * Instantiates a new Urban address. + */ + public UrbanAddress() { + super(); + } + + /** + * Instantiates a new Urban address. + * + * @param city the city + * @param state the state + * @param zipCode the zipCode + * @param street the street + * @param streetNumber the street number + * @param complement the complement + * @param neighborhood the neighborhood + */ + public UrbanAddress(String city, String state, String zipCode, String street, int streetNumber, + String complement, String neighborhood) { + super(city, state, zipCode); + this.street = street; + this.streetNumber = streetNumber; + this.complement = complement; + this.neighborhood = neighborhood; + } + + /** + * Gets street. + * + * @return the street + */ + public String getStreet() { + return street; + } + + /** + * Sets street. + * + * @param street the street + */ + public void setStreet(String street) { + this.street = street; + } + + /** + * Gets street number. + * + * @return the street number + */ + public int getStreetNumber() { + return streetNumber; + } + + /** + * Sets street number. + * + * @param streetNumber the street number + */ + public void setStreetNumber(int streetNumber) { + this.streetNumber = streetNumber; + } + + /** + * Gets complement. + * + * @return the complement + */ + public String getComplement() { + return complement; + } + + /** + * Sets complement. + * + * @param complement the complement + */ + public void setComplement(String complement) { + this.complement = complement; + } + + /** + * Gets neighborhood. + * + * @return the neighborhood + */ + public String getNeighborhood() { + return neighborhood; + } + + /** + * Sets neighborhood. + * + * @param neighborhood the neighborhood + */ + public void setNeighborhood(String neighborhood) { + this.neighborhood = neighborhood; + } +} \ No newline at end of file