package net.ihe.xds.front.end.action; import java.io.IOException; import java.io.Serializable; import java.net.InetAddress; import java.net.MalformedURLException; import java.util.List; import javax.ejb.Remove; import javax.ejb.Stateful; import javax.persistence.EntityManager; import net.ihe.xds.front.end.model.SystemConfiguration; import org.jboss.seam.Component; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.faces.FacesMessages; import org.jboss.seam.log.Log; /** * @author R�gis Lucas > INRIA Rennes IHE development Project * */ @Stateful @Name("configurationSystemManager") @Scope(ScopeType.SESSION) public class ConfigurationSystemManager implements ConfigurationSystemManagerLocal,Serializable{ /** * */ private static final long serialVersionUID = 6L; /** Logger */ @Logger private Log log; //~ Attribute ///////////////// ////////////////////////////////////////////////////// private int id; private String systemName; private String systemIP; private String systemURL; private int systemPort; private SystemConfiguration selectedSystem; private boolean systemSecure; public boolean getSystemSecure() { return systemSecure; } public void setSystemSecure(boolean secure) { this.systemSecure = secure; } public int getId() { return id; } public void setId(int id) { this.id = id; } public SystemConfiguration getSelectedSystem() { return selectedSystem; } public void setSystemName(String systemName){ this.systemName=systemName; } public String getSystemName(){ return systemName; } public void setSystemIP(String systemIP){ this.systemIP=systemIP; } public String getSystemIP(){ return systemIP; } public void setSystemURL(String systemURL){ this.systemURL=systemURL; } public String getSystemURL(){ return systemURL; } public void setSystemPort(int systemPort){ this.systemPort=systemPort; } public int getSystemPort(){ return systemPort; } public List getListSystemConfiguration(){ List lm = SystemConfiguration.listAllSystemConfiguration(); return lm; } public String getSystemName(SystemConfiguration currentSystem){ return currentSystem.getName(); } public String getSystemIP(SystemConfiguration currentSystem){ return currentSystem.getIp(); } public String getSystemURL(SystemConfiguration currentSystem){ return currentSystem.getUrl(); } public int getSystemPort(SystemConfiguration currentSystem){ return currentSystem.getPort(); } public boolean getSystemSecure(SystemConfiguration currentSystem){ return currentSystem.getSecure(); } public void setSelectedSystem(SystemConfiguration selectedSystem) { this.selectedSystem = selectedSystem; systemName= selectedSystem.getName(); systemIP=selectedSystem.getIp(); systemPort=selectedSystem.getPort(); systemURL=selectedSystem.getUrl(); systemSecure=selectedSystem.getSecure(); //id=selectedSystem.getId(); } public String createNewSystemConfiguration() { systemIP=""; systemName=""; systemPort=0; systemURL=""; systemSecure=false; selectedSystem=null; return "/configuration/addConfiguration.xhtml" ; } public String editSystemConfigurationButtonClick( SystemConfiguration inSystemConfiguration ){ setSelectedSystem(inSystemConfiguration ); return "/configuration/addConfiguration.xhtml" ; } public boolean validateIP(String ipAddress) throws IOException{ InetAddress target = InetAddress.getByName(ipAddress); return target.isReachable(1000); } public void deleteSystemConfiguration(SystemConfiguration currentSystem) { SystemConfiguration.deleteSystemConfiguration(currentSystem); } /* (non-Javadoc) * @see net.ihe.xdrsrc.action.ConfigurationSystemManagerLocal#addEditSystemConfiguration() */ public String addEditSystemConfiguration() { EntityManager entityManager=(EntityManager)Component.getInstance("entityManager"); if(selectedSystem!=null) { SystemConfiguration systemeConfiguration = SystemConfiguration.getSystemConfigurationById(selectedSystem.getId()); systemeConfiguration.setIp(systemIP); systemeConfiguration.setName(systemName); systemeConfiguration.setPort(systemPort); systemeConfiguration.setUrl(systemURL); systemeConfiguration.setSecure(systemSecure); systemeConfiguration = entityManager.merge(systemeConfiguration); entityManager.flush(); } else { SystemConfiguration systemeConfigurationCreate =new SystemConfiguration(systemName, systemIP, systemURL, systemPort,systemSecure); entityManager.merge(systemeConfigurationCreate); entityManager.flush(); } //FacesMessages.instance().add("#{messages['xds.front.end.configurationManager.configurationsaved']}"); return "/configuration/systemconfiguration.xhtml" ; } public String cancelAction() { return "/configuration/systemconfiguration.xhtml" ; } // destroy method /////////////////////////////////////////////////////////////////// @Destroy @Remove public void destroy() { log.info("destroy"); } }