Newer
Older
package it.inaf.oats.ia2.tapschemamanager.webapp;
import it.inaf.oats.ia2.tapschemamanager.datalayer.Credentials;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import javax.annotation.PostConstruct;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
/**
*
* @author Sonia Zorba <zorba at oats.inaf.it>
*/
@Named("credentialsInsertion")
@RequestScoped
public class CredentialsBean implements Serializable {
Sonia Zorba
committed
private static final long serialVersionUID = -2688980249773483198L;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@Inject
Conversation conversation;
@Inject
SchemaSelectionBean schemaSelectionBean;
private String loginError;
private Credentials credentials;
@PostConstruct
public void init() {
if (!conversation.isTransient()) {
conversation.end();
}
credentials = new Credentials();
}
public String getHostname() {
return credentials.getHostname();
}
public void setHostname(String hostname) {
credentials.setHostname(hostname);
}
public int getPort() {
return credentials.getPort();
}
public void setPort(int port) {
credentials.setPort(port);
}
public String getUsername() {
return credentials.getUsername();
}
public void setUsername(String username) {
credentials.setUsername(username);
}
public String getPassword() {
return credentials.getPassword();
}
public void setPassword(String password) {
credentials.setPassword(password);
}
public String getLoginError() {
return loginError;
}
public String login() {
loginError = null;
try {
Connection connection = credentials.getConnection();
connection.close();
conversation.begin();
schemaSelectionBean.setCredentials(credentials);
return "schemaSelection.xhtml?faces-redirect=true";
} catch (SQLException e) {
loginError = "Connection error: " + e.getMessage();
return "index.xhtml?faces-redirect=true";
}
}
}