Skip to content

Instantly share code, notes, and snippets.

@Parsoa
Created June 9, 2017 06:32
Show Gist options
  • Save Parsoa/f463fbef548f3a678c1e067e9aad5b21 to your computer and use it in GitHub Desktop.
Save Parsoa/f463fbef548f3a678c1e067e9aad5b21 to your computer and use it in GitHub Desktop.
Spring Boot Entity List
package com.collective.foundation.entities ;
import java.util.List ;
import javax.persistence.* ;
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="COMPONENT_TYPE")
@DiscriminatorValue("COMPONENT")
public class Component {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id ;
@ManyToOne
private Supplier supplier ;
@OneToMany(mappedBy="component")
private List<ComponentInstance> instances ;
private String name ;
private double price ;
private int minStock ;
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public Long getId() {
return id ;
}
public void setId(Long id) {
this.id = id ;
}
public String getName() {
return name ;
}
public void setName(String name) {
this.name = name;
}
public Supplier getSupplier() {
return supplier;
}
public void setSupplier(Supplier supplier) {
this.supplier = supplier;
}
public int getMinStock() {
return minStock;
}
public void setMinStock(int minStock) {
this.minStock = minStock;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public List<ComponentInstance> getInstances() {
return instances;
}
public void setInstances(List<ComponentInstance> instances) {
this.instances = instances;
}
}
package com.collective.foundation.entities ;
import java.util.Date ;
import javax.persistence.* ;
import com.collective.foundation.warehousing.ComponentInstanceRepository ;
@Entity
public class ComponentInstance {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id ;
@ManyToOne
private Component component ;
@OneToOne
private Order order ;
@OneToOne
private ComponentOrder componentOrder ;
@Temporal(TemporalType.DATE)
private Date entryDate ;
@Temporal(TemporalType.DATE)
private Date exitDate ;
private Boolean reserved ;
private Boolean present ;
// ================================================================================================================ \\
// =============================================== Mutators ======================================================= \\
// ================================================================================================================ \\
public void reserveForOrder(ComponentInstanceRepository componentInstanceRepository, Order order) {
this.setReserved(true) ;
this.setOrder(order) ;
componentInstanceRepository.save(this) ;
}
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Component getComponent() {
return component;
}
public void setComponent(Component component) {
this.component = component;
}
public Boolean getReserved() {
return reserved;
}
public void setReserved(Boolean reserved) {
this.reserved = reserved;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public Boolean getPresent() {
return present;
}
public void setPresent(Boolean present) {
this.present = present;
}
public Date getEntryDate() {
return entryDate;
}
public void setEntryDate(Date entryDate) {
this.entryDate = entryDate;
}
public Date getExitDate() {
return exitDate;
}
public void setExitDate(Date exitDate) {
this.exitDate = exitDate;
}
public ComponentOrder getComponentOrder() {
return componentOrder;
}
public void setComponentOrder(ComponentOrder componentOrder) {
this.componentOrder = componentOrder;
}
}
package com.collective.foundation.entities ;
import javax.persistence.* ;
@Entity
public class ComponentOrder {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id ;
@ManyToOne
private Component component ;
@ManyToOne
private Supplier supplier ;
@ManyToOne
private Order order ;
private Integer count ;
private Boolean reserved ;
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Component getComponent() {
return component;
}
public void setComponent(Component component) {
this.component = component;
}
public Supplier getSupplier() {
return supplier;
}
public void setSupplier(Supplier supplier) {
this.supplier = supplier;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public Boolean getReserved() {
return reserved;
}
public void setReserved(Boolean reserved) {
this.reserved = reserved;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
}
package com.collective.foundation.entities ;
import org.springframework.security.core.GrantedAuthority ;
import org.springframework.security.core.authority.SimpleGrantedAuthority ;
import org.springframework.security.core.userdetails.UserDetails ;
import java.util.Collection ;
import java.util.Arrays ;
import javax.persistence.* ;
@Entity
@DiscriminatorValue("CUSTOMER")
public class Customer extends User {
private String address ;
private String phoneNumber ;
private String nationalId ;
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return Arrays.asList(new SimpleGrantedAuthority("CUSTOMER"));
}
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getNationalId() {
return nationalId;
}
public void setNationalId(String nationalId) {
this.nationalId = nationalId;
}
}
package com.collective.foundation.entities ;
import javax.persistence.* ;
@Entity
@DiscriminatorValue("HARDWARE")
public class HardwareComponent extends Component {
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
}
package com.collective.foundation.entities ;
import javax.persistence.* ;
@Entity
@DiscriminatorValue("HARDWARE_GRAPHICS")
public class HardwareGraphicsComponent extends HardwareComponent {
private double frequency ;
private int cores ;
private double bandwidth ;
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public double getFrequency() {
return frequency;
}
public void setFrequency(double frequency) {
this.frequency = frequency;
}
public int getCores() {
return cores;
}
public void setCores(int cores) {
this.cores = cores;
}
public double getBandwidth() {
return bandwidth;
}
public void setBandwidth(double bandwidth) {
this.bandwidth = bandwidth;
}
}
package com.collective.foundation.entities ;
import javax.persistence.* ;
@Entity
@DiscriminatorValue("HARDWARE_PROCESSING")
public class HardwareProcessingComponent extends Component {
private double frequency ;
private int cores ;
private long cacheSize ;
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public double getFrequency() {
return frequency;
}
public void setFrequency(double frequency) {
this.frequency = frequency;
}
public int getCores() {
return cores;
}
public void setCores(int cores) {
this.cores = cores;
}
public long getCacheSize() {
return cacheSize;
}
public void setCacheSize(long cacheSize) {
this.cacheSize = cacheSize;
}
}
package com.collective.foundation.entities ;
import javax.persistence.* ;
@Entity
@DiscriminatorValue("HARDWARE_RAM")
public class HardwareRamComponent extends Component {
private long capacity ;
private double frequency ;
private double bandwidth ;
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public long getCapacity() {
return capacity;
}
public void setCapacity(long capacity) {
this.capacity = capacity;
}
public double getFrequency() {
return frequency;
}
public void setFrequency(double frequency) {
this.frequency = frequency;
}
public double getBandwidth() {
return bandwidth;
}
public void setBandwidth(double bandwidth) {
this.bandwidth = bandwidth;
}
}
package com.collective.foundation.entities ;
import javax.persistence.* ;
@Entity
@DiscriminatorValue("HARDWARE_STORAGE")
public class HardwareStorageComponent extends Component {
private String type ;
private double frequency ;
private long capacity ;
private double bandwidth ;
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public double getFrequency() {
return frequency;
}
public void setFrequency(double frequency) {
this.frequency = frequency;
}
public long getCapacity() {
return capacity;
}
public void setCapacity(long capacity) {
this.capacity = capacity;
}
public double getBandwidth() {
return bandwidth;
}
public void setBandwidth(double bandwidth) {
this.bandwidth = bandwidth;
}
}
package com.collective.foundation.entities ;
import java.util.Date ;
import javax.persistence.* ;
@Entity
public class Invoice {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id ;
@OneToOne
private Order order ;
@OneToOne
private Customer customer ;
@Temporal(TemporalType.DATE)
private Date issueDate ;
private String status ;
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Date getIssueDate() {
return issueDate;
}
public void setIssueDate(Date issueDate) {
this.issueDate = issueDate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
package com.collective.foundation.entities ;
import org.springframework.security.core.GrantedAuthority ;
import org.springframework.security.core.authority.SimpleGrantedAuthority ;
import org.springframework.security.core.userdetails.UserDetails ;
import java.util.Collection ;
import java.util.Arrays ;
import javax.persistence.* ;
@Entity
@DiscriminatorValue("MANAGER")
public class Manager extends User {
}
package com.collective.foundation.entities ;
import java.util.Date ;
import javax.persistence.* ;
import com.collective.foundation.scm.OrderRepository ;
@Entity
public class Order {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id ;
@OneToOne
private Product product ;
@OneToOne
private Customer customer ;
@OneToOne(mappedBy="order")
private Invoice invoice ;
@Temporal(TemporalType.DATE)
private Date creationDate ;
@Temporal(TemporalType.DATE)
private Date confirmationDate ;
@Temporal(TemporalType.DATE)
private Date assemblyDate ;
@Temporal(TemporalType.DATE)
private Date shippingDate ;
private String status ;
// ================================================================================================================ \\
// =================================================== Mutators =================================================== \\
// ================================================================================================================ \\
public void changeStatus(OrderRepository orderRepository, String status) {
this.setStatus(status) ;
orderRepository.save(this) ;
}
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Invoice getInvoice() {
return invoice;
}
public void setInvoice(Invoice invoice) {
this.invoice = invoice;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getConfirmationDate() {
return confirmationDate;
}
public void setConfirmationDate(Date confirmationDate) {
this.confirmationDate = confirmationDate;
}
public Date getAssemblyDate() {
return assemblyDate;
}
public void setAssemblyDate(Date assemblyDate) {
this.assemblyDate = assemblyDate;
}
public Date getShippingDate() {
return shippingDate;
}
public void setShippingDate(Date shippingDate) {
this.shippingDate = shippingDate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
package com.collective.foundation.entities ;
import java.util.List ;
import javax.persistence.* ;
@Entity
public class Product {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id ;
@OneToOne
private SoftwareComponent operatingSystem ;
@OneToOne
private HardwareProcessingComponent hardwareProcessingComponent ;
@OneToOne
private HardwareRamComponent hardwareRamComponent ;
@OneToOne
private HardwareGraphicsComponent hardwareGraphicsComponent ;
@OneToOne
private HardwareStorageComponent hardwareStorageComponent ;
@OneToMany
private List<SoftwareComponent> softwareComponents ;
private String name ;
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public SoftwareComponent getOperatingSystem() {
return operatingSystem;
}
public void setOperatingSystem(SoftwareComponent operatingSystem) {
this.operatingSystem = operatingSystem;
}
public HardwareProcessingComponent getHardwareProcessingComponent() {
return hardwareProcessingComponent;
}
public void setHardwareProcessingComponent(HardwareProcessingComponent hardwareProcessingComponent) {
this.hardwareProcessingComponent = hardwareProcessingComponent;
}
public HardwareRamComponent getHardwareRamComponent() {
return hardwareRamComponent;
}
public void setHardwareRamComponent(HardwareRamComponent hardwareRamComponent) {
this.hardwareRamComponent = hardwareRamComponent;
}
public HardwareGraphicsComponent getHardwareGraphicsComponent() {
return hardwareGraphicsComponent;
}
public void setHardwareGraphicsComponent(HardwareGraphicsComponent hardwareGraphicsComponent) {
this.hardwareGraphicsComponent = hardwareGraphicsComponent;
}
public HardwareStorageComponent getHardwareStorageComponent() {
return hardwareStorageComponent;
}
public void setHardwareStorageComponent(HardwareStorageComponent hardwareStorageComponent) {
this.hardwareStorageComponent = hardwareStorageComponent;
}
public List<SoftwareComponent> getSoftwareComponents() {
return softwareComponents;
}
public void setSoftwareComponents(List<SoftwareComponent> softwareComponents) {
this.softwareComponents = softwareComponents;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.collective.foundation.entities ;
import java.util.List ;
import java.util.Date ;
import javax.persistence.* ;
@Entity
public class Report {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id ;
@Temporal(TemporalType.DATE)
private Date issueDate ;
private String content ;
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getIssueDate() {
return issueDate;
}
public void setIssueDate(Date issueDate) {
this.issueDate = issueDate;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
package com.collective.foundation.entities ;
import org.springframework.security.core.GrantedAuthority ;
import org.springframework.security.core.authority.SimpleGrantedAuthority ;
import org.springframework.security.core.userdetails.UserDetails ;
import java.util.Collection ;
import java.util.Arrays ;
import javax.persistence.* ;
@Entity
@DiscriminatorValue("SCM_MANAGER")
public class ScmManager extends Manager {
}
package com.collective.foundation.entities ;
import org.springframework.security.core.GrantedAuthority ;
import org.springframework.security.core.authority.SimpleGrantedAuthority ;
import org.springframework.security.core.userdetails.UserDetails ;
import java.util.Collection ;
import java.util.Arrays ;
import javax.persistence.* ;
@Entity
@DiscriminatorValue("SCM_STAFF")
public class ScmStaff extends Staff {
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return Arrays.asList(new SimpleGrantedAuthority("SCM_STAFF")) ;
}
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
}
package com.collective.foundation.entities ;
import javax.persistence.* ;
@Entity
@DiscriminatorValue("SOFTWARE")
public class SoftwareComponent extends Component {
private String type ;
private String targetOperatingSystem ;
private String version ;
private String developer ;
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTargetOperatingSystem() {
return targetOperatingSystem;
}
public void setTargetOperatingSystem(String targetOperatingSystem) {
this.targetOperatingSystem = targetOperatingSystem;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getDeveloper() {
return developer;
}
public void setDeveloper(String developer) {
this.developer = developer;
}
}
package com.collective.foundation.entities ;
import org.springframework.security.core.GrantedAuthority ;
import org.springframework.security.core.authority.SimpleGrantedAuthority ;
import org.springframework.security.core.userdetails.UserDetails ;
import java.util.Collection ;
import java.util.Arrays ;
import javax.persistence.* ;
@Entity
@DiscriminatorValue("STAFF")
public class Staff extends User {
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return Arrays.asList(new SimpleGrantedAuthority("STAFF"));
}
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
}
package com.collective.foundation.entities ;
import java.util.List ;
import java.util.ArrayList ;
import javax.persistence.* ;
import com.collective.foundation.warehousing.ComponentRepository;
@Entity
public class Supplier {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id ;
private String name ;
private String address ;
private String phoneNumber ;
private String bankAccount ;
@OneToMany(mappedBy = "supplier")
private List<Component> components = new ArrayList<>() ;
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
@Override
public String toString() {
String s = "=========== Provider Instance ========= \n" ;
s += "id: " + this.id + "\n" ;
s += "address: " + this.address + "\n" ;
s += "phoneNumber: " + this.phoneNumber + "\n" ;
s += "bankAccount: " + this.bankAccount + "\n" ;
return s ;
}
// ================================================================================================================ \\
// ================================================ Mutators ====================================================== \\
// ================================================================================================================ \\
public void addComponent(Component component) {
components.add(component) ;
component.setSupplier(this) ;
}
public void updateComponentCost(ComponentRepository componentRepository, Component component) {
// needs to generate
}
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getBankAccount() {
return bankAccount;
}
public void setBankAccount(String bankAccount) {
this.bankAccount = bankAccount;
}
public List<Component> getComponents() {
return components;
}
public void setComponents(List<Component> components) {
this.components = components;
}
}
package com.collective.foundation.entities ;
import org.springframework.security.core.GrantedAuthority ;
import org.springframework.security.core.authority.SimpleGrantedAuthority ;
import org.springframework.security.core.userdetails.UserDetails ;
import java.util.Collection ;
import java.util.Arrays ;
import javax.persistence.* ;
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="USER_TYPE")
@DiscriminatorValue("USER")
public class User implements UserDetails {
@Id
private String username ;
private String password ;
private String firstName ;
private String lastName ;
private String email ;
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return Arrays.asList(new SimpleGrantedAuthority("USER"));
}
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
@Override
public boolean isAccountNonExpired() {
return true ;
}
@Override
public boolean isAccountNonLocked() {
return true ;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
// ================================================================================================================ \\
// ================================================================================================================ \\
// ================================================================================================================ \\
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
package com.collective.foundation.entities ;
import org.springframework.security.core.GrantedAuthority ;
import org.springframework.security.core.authority.SimpleGrantedAuthority ;
import org.springframework.security.core.userdetails.UserDetails ;
import java.util.Collection ;
import java.util.Arrays ;
import javax.persistence.* ;
@Entity
@DiscriminatorValue("WAREHOUSE_MANAGER")
public class WarehouseManager extends Manager {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment