Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package it.inaf.oats.ia2.tapschemamanager.webapp;
import it.inaf.oats.ia2.tapschemamanager.businesslayer.TapSchema;
import it.inaf.oats.ia2.tapschemamanager.datalayer.Credentials;
import it.inaf.oats.ia2.tapschemamanager.datalayer.DataProvider;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
/**
*
* @author Sonia Zorba <zorba at oats.inaf.it>
*/
@Named("schemaSelection")
@ConversationScoped
public class SchemaSelectionBean implements Serializable {
@Inject
private Conversation conversation;
@Inject
TapSchemaEditingBean tapSchemaEditingBean;
private Credentials credentials;
private String selectedRadioOption;
// For editing
private List<String> allTAPSchemas;
private String selectedTAPSchema;
private String exposedSchemas;
// For creation
private String tapSchemaName;
private List<String> allSchemas;
private List<String> selectedSchemas;
@PostConstruct
public void init() {
selectedRadioOption = "edit";
exposedSchemas = "";
}
public void onPageLoad() {
FacesContext fc = FacesContext.getCurrentInstance();
final boolean ajaxRequest = fc.getPartialViewContext().isAjaxRequest();
final boolean validationFailed = fc.isValidationFailed();
if (!ajaxRequest && !validationFailed) {
Connection connection = null;
try {
connection = credentials.getConnection();
allSchemas = DataProvider.getAllSchemasNames(connection);
setSelectedSchemas(new ArrayList<String>());
allTAPSchemas = DataProvider.getAllTAPSchemasNames(connection, allSchemas);
if (!allTAPSchemas.isEmpty()) {
this.selectedTAPSchema = allTAPSchemas.get(0);
loadExposedSchemas(connection);
}
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}
public void loadExposedSchemas(Connection connection) throws SQLException {
List<String> schemas = DataProvider.getExposedSchemas(connection, selectedTAPSchema);
exposedSchemas = "";
for (int i = 0; i < schemas.size(); i++) {
exposedSchemas += schemas.get(i);
if (i < schemas.size() - 1) {
exposedSchemas += ", ";
}
}
}
public List<String> getAllTAPSchemas() {
return allTAPSchemas;
}
public List<String> getAllSchemas() {
return allSchemas;
}
public String getExposedSchemas() {
return exposedSchemas;
}
public String getSelectedRadioOption() {
return selectedRadioOption;
}
public void setSelectedRadioOption(String selectedRadioOption) {
this.selectedRadioOption = selectedRadioOption;
}
public String getSelectedTAPSchema() {
return selectedTAPSchema;
}
public void setSelectedTAPSchema(String selectedTAPSchema) {
this.selectedTAPSchema = selectedTAPSchema;
Connection connection = null;
try {
connection = credentials.getConnection();
loadExposedSchemas(connection);
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
public List<String> getSelectedSchemas() {
return selectedSchemas;
}
public void setSelectedSchemas(List<String> selectedSchemas) {
this.selectedSchemas = selectedSchemas;
}
private String loadTapSchema(TapSchema tapSchema) {
tapSchemaEditingBean.setTapSchema(tapSchema);
return "tapSchemaEditing.xhtml?faces-redirect=true";
}
public String edit() {
try {
return loadTapSchema(new TapSchema(credentials, selectedTAPSchema, true));
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public String create() {
try {
TapSchema tapSchema = new TapSchema(credentials, tapSchemaName, false);
for (String selectedSchema : selectedSchemas) {
tapSchema.addEntityWrapper(selectedSchema);
}
return loadTapSchema(tapSchema);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public String getTapSchemaName() {
return tapSchemaName;
}
public void setTapSchemaName(String tapSchemaName) {
this.tapSchemaName = tapSchemaName;
}
public Credentials getCredentials() {
return credentials;
}
public void setCredentials(Credentials credentials) {
this.credentials = credentials;
}
public String logout() {
conversation.end();
return "index.xhtml?faces-redirect=true";
}
}