package net.ihe.xds.front.end.model; import java.io.Serializable; import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Query; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import org.hibernate.validator.NotNull; import org.jboss.seam.Component; import org.jboss.seam.annotations.Name; /** * @author R�gis Lucas > INRIA Rennes IHE development Project * */ @Entity @Name("simulatorsConfiguration") @Table(name = "xds_simulators_configuration", schema = "public") @SequenceGenerator(name = "xds_simulators_configuration_sequence", sequenceName = "xds_simulators_configuration_id_seq", allocationSize = 1) public class SystemConfiguration implements Serializable { /** * */ private static final long serialVersionUID = 5444985974251904657L; // attributes //////////////////////////////////////////////////////////////////////////// /** Id of this object */ @Id @Column(name = "id", unique = true, nullable = false) @NotNull @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "xds_simulators_configuration_sequence") private Integer id; @Column(name = "name") private String name; @Column(name = "ip") private String ip; @Column(name = "url") private String url; @Column(name = "port") private int port; @Column(name="secure") private boolean secure; // constructors //////////////////////////////////////////////////////////////////////////// public SystemConfiguration (){ } /** * @param name - System Configuration Name * @param ip - System Configuration Ip * @param url - System Configuration url * @param port - System Configuration port * @param secure - Boolean System is secure or not secure */ public SystemConfiguration (String name, String ip, String url,int port,boolean secure) { super(); this.name = name; this.ip = ip; this.url=url; this.port=port; this.secure=secure; } // getters and setters ////////////////////////////////////////////////////////////////////// public boolean getSecure() { return secure; } public void setSecure(boolean secure) { this.secure = secure; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getIp() { return ip; } public void setIp(String ip) { this.ip = ip; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public int getPort() { return port; } public void setPort(int port) { this.port = port; } // hashcode and equals ////////////////////////////////////////////////////////////////////// @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((ip == null) ? 0 : ip.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + port; result = prime * result + (secure ? 1231 : 1237); result = prime * result + ((url == null) ? 0 : url.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; SystemConfiguration other = (SystemConfiguration) obj; if (ip == null) { if (other.ip != null) return false; } else if (!ip.equals(other.ip)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (port != other.port) return false; if (secure != other.secure) return false; if (url == null) { if (other.url != null) return false; } else if (!url.equals(other.url)) return false; return true; } // methods /////////////////////////////////////////////////////////////////////////////////// /** * @return */ @SuppressWarnings("unchecked") public static List listAllSystemConfiguration(){ EntityManager em = (EntityManager) Component.getInstance("entityManager"); Query query = em.createQuery("SELECT systemconfig FROM SystemConfiguration systemconfig"); List aipList = (List) query.getResultList(); return aipList; } /** * @param systemConfiguration - SystemConfiguration to delete */ public static void deleteSystemConfiguration(SystemConfiguration systemConfiguration){ EntityManager entityManager=(EntityManager)Component.getInstance("entityManager"); SystemConfiguration systemConfig = (SystemConfiguration)entityManager.find(SystemConfiguration.class, systemConfiguration.getId()); entityManager.remove(systemConfig); entityManager.flush(); } /** * @param id - System Configuration Id * @return */ public static SystemConfiguration getSystemConfigurationById(int id){ SystemConfiguration result = null; EntityManager entityManager=(EntityManager)Component.getInstance("entityManager"); Query queryContact = entityManager.createQuery("SELECT systemconfig From SystemConfiguration systemconfig WHERE systemconfig.id="+id+""); List lac = (List)queryContact.getResultList(); if (lac != null){ if (lac.size()>0){ result = lac.get(0); } } return result; } /** * @param name - System Configuration Name * @return */ public static SystemConfiguration getSystemConfigurationByName(String name){ SystemConfiguration result = null; EntityManager entityManager=(EntityManager)Component.getInstance("entityManager"); Query queryContact = entityManager.createQuery("SELECT systemconfig From SystemConfiguration systemconfig WHERE systemconfig.name='"+name+"'"); List lac = (List)queryContact.getResultList(); if (lac != null){ if (lac.size()>0){ result = lac.get(0); } } return result; } }