hs.hsadmin/hsarback/src/de/hsadmin/mods/pac/Pac.java

283 lines
6.1 KiB
Java
Raw Normal View History

2010-10-01 21:52:51 +02:00
package de.hsadmin.mods.pac;
import static javax.persistence.CascadeType.ALL;
import static javax.persistence.FetchType.EAGER;
import static javax.persistence.FetchType.LAZY;
import static javax.persistence.GenerationType.SEQUENCE;
import java.io.Serializable;
import java.util.Date;
2011-03-22 23:02:06 +01:00
import java.util.HashSet;
import java.util.Set;
2010-10-01 21:52:51 +02:00
2010-10-06 15:06:01 +02:00
import javax.persistence.Column;
import javax.persistence.Entity;
2010-10-01 21:52:51 +02:00
import javax.persistence.EntityManager;
2010-10-06 15:06:01 +02:00
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.EntityInfo;
2010-10-01 21:52:51 +02:00
import de.hsadmin.mods.cust.Customer;
import de.hsadmin.mods.user.UnixUser;
2010-10-06 15:06:01 +02:00
@Entity(name = "Pacs")
@Table(name = "packet")
@SequenceGenerator(name = "PacsSeqGen", sequenceName = "packet_packet_id_seq")
@EntityInfo(name = "Paket")
public class Pac extends AbstractEntity implements Serializable {
2010-10-01 21:52:51 +02:00
private static final long serialVersionUID = 1201899873300190132L;
2010-10-06 15:06:01 +02:00
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "PacsSeqGen")
2011-03-23 13:12:13 +01:00
@Column(name = "packet_id", columnDefinition = "integer")
2010-10-01 21:52:51 +02:00
private long id;
2010-10-06 15:06:01 +02:00
@Column(name = "packet_name", unique = true)
2010-10-01 21:52:51 +02:00
private String name;
2010-10-06 15:06:01 +02:00
@JoinColumn(name = "bp_id")
@ManyToOne(fetch = EAGER)
2010-10-01 21:52:51 +02:00
private Customer customer;
2010-10-06 15:06:01 +02:00
@JoinColumn(name = "hive_id")
@ManyToOne(fetch = EAGER)
2010-10-01 21:52:51 +02:00
private Hive hive;
2010-10-06 15:06:01 +02:00
@Column(name = "created")
@Temporal(TemporalType.DATE)
2010-10-01 21:52:51 +02:00
private Date created;
2010-10-06 15:06:01 +02:00
@Column(name = "cancelled", nullable = true)
@Temporal(TemporalType.DATE)
2010-10-01 21:52:51 +02:00
private Date cancelled;
2010-10-06 15:06:01 +02:00
@Column(name = "order_number", nullable = true)
2010-10-01 21:52:51 +02:00
private String orderNo;
2010-10-06 15:06:01 +02:00
@Column(name = "webserver_group", nullable = true)
2010-10-01 21:52:51 +02:00
private String webserverGroup;
2010-10-06 15:06:01 +02:00
@JoinColumn(name = "cur_inet_addr_id", nullable = true)
@ManyToOne(fetch = EAGER)
2010-10-01 21:52:51 +02:00
private INetAddress curINetAddr;
2010-10-06 15:06:01 +02:00
@JoinColumn(name = "old_inet_addr_id", nullable = true)
@ManyToOne(fetch = EAGER)
2010-10-01 21:52:51 +02:00
private INetAddress oldINetAddr;
2011-03-22 23:02:06 +01:00
@OneToMany(fetch = LAZY, cascade = ALL, mappedBy="pac")
private Set<PacComponent> pacComponents;
2010-10-01 21:52:51 +02:00
2011-03-22 23:02:06 +01:00
@OneToMany(fetch = LAZY, cascade = ALL, mappedBy="pac")
private Set<UnixUser> unixUser;
2010-10-01 21:52:51 +02:00
2011-03-22 23:02:06 +01:00
@Transient
private BasePac basepac;
2010-10-01 21:52:51 +02:00
public Pac() {
2011-05-19 18:03:59 +02:00
basepac = new BasePac();
2010-10-01 21:52:51 +02:00
}
public Pac(String name, Customer cust, BasePac basePac, Hive hive) {
this.name = name;
this.customer = cust;
this.hive = hive;
2011-03-22 23:02:06 +01:00
this.created = new Date();
2010-10-01 21:52:51 +02:00
this.webserverGroup = "httpd";
this.curINetAddr = hive.getInetAddr();
2011-03-22 23:02:06 +01:00
pacComponents = new HashSet<PacComponent>();
Date today = new Date();
2010-10-01 21:52:51 +02:00
for (Component comp : basePac.getComponents()) {
PacComponent pacComp = new PacComponent(basePac,
comp.getBaseComponent(), this, comp.getDefaultQuantity(),
today, null);
pacComponents.add(pacComp);
System.err.println("TRACE [Pac]: added pacComp " + pacComp + " to "
+ getName());
}
}
public static String createQueryFromStringKey(String humanKey) {
return "obj.name='" + humanKey + "'";
}
@Override
public String createStringKey() {
return getName();
}
@Override
public long id() {
return id;
}
public long getId() {
return id;
}
protected void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Hive getHive() {
return hive;
}
public void setHive(Hive hive) {
this.hive = hive;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getCancelled() {
return cancelled;
}
public void setCancelled(Date cancelled) {
this.cancelled = cancelled;
}
public String getOrderNo() {
return orderNo;
}
public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}
public String getwebserverGroup() {
return webserverGroup;
}
public void setwebserverGroup(String webserverGroup) {
this.webserverGroup = webserverGroup;
}
public INetAddress getCurINetAddr() {
return curINetAddr;
}
public void setCurINetAddr(INetAddress curINetAddr) {
this.curINetAddr = curINetAddr;
}
public INetAddress getOldINetAddr() {
return oldINetAddr;
}
public void setOldINetAddr(INetAddress oldINetAddr) {
this.oldINetAddr = oldINetAddr;
}
2011-03-22 23:02:06 +01:00
public BasePac getBasepac() {
if (basepac == null) {
Set<PacComponent> pacComps = getPacComponents();
if (pacComps != null) {
basepac = pacComps.iterator().next().getBasePac();
}
}
return basepac;
2010-10-01 21:52:51 +02:00
}
2011-03-22 23:02:06 +01:00
public void setBasepac(BasePac basepac) {
this.basepac = basepac;
2010-10-01 21:52:51 +02:00
}
2011-03-22 23:02:06 +01:00
public Set<PacComponent> getPacComponents() {
2010-10-01 21:52:51 +02:00
return pacComponents;
}
2011-03-22 23:02:06 +01:00
public void setPacComponents(Set<PacComponent> pacComponents) {
2010-10-01 21:52:51 +02:00
this.pacComponents = pacComponents;
}
public PacComponent getPacComponent(String feature) {
for (PacComponent pc : getPacComponents())
if (feature.equals(pc.getBaseComponent().getFeature()))
return pc;
return null;
}
2011-03-22 23:02:06 +01:00
public Set<UnixUser> getUnixUser() {
2010-10-01 21:52:51 +02:00
return unixUser;
}
2011-03-22 23:02:06 +01:00
public void setUnixUser(Set<UnixUser> unixUser) {
2010-10-01 21:52:51 +02:00
this.unixUser = unixUser;
}
public String toString() {
return super.toString() + "{ name=" + name + " }";
}
@Override
public boolean isNew() {
return id == 0;
}
@Override
public String getHiveName() {
if (isNew())
return null;
else
return getHive().getHiveName();
}
@Override
public UnixUser owningUser(EntityManager em) {
return customer.owningUser(em);
}
public UnixUser getAdminUser(EntityManager em) {
return null;
}
public boolean isReadAllowedFor(UnixUser loginUser) {
return getName().equals(loginUser.getName())
2011-03-30 18:26:43 +02:00
|| getCustomer().getName().equals(loginUser.getName())
2010-10-01 21:52:51 +02:00
|| super.isReadAllowedFor(loginUser);
}
public static String restriction() {
return
2010-10-06 15:06:01 +02:00
// all pacs of customer
"obj.customer.name=:loginUserName OR " +
// pac of packet admin
"obj.name=:loginUserName";
2010-10-01 21:52:51 +02:00
}
}