Newer
Older
package it.inaf.oats.ia2.tapschemamanager.webapp;
Sonia Zorba
committed
import it.inaf.oats.ia2.tapschemamanager.businesslayer.Column;
import it.inaf.oats.ia2.tapschemamanager.businesslayer.EntityWrapper;
import it.inaf.oats.ia2.tapschemamanager.businesslayer.EntityWrapperContainer;
import it.inaf.oats.ia2.tapschemamanager.businesslayer.Status;
import it.inaf.oats.ia2.tapschemamanager.businesslayer.Table;
import it.inaf.oats.ia2.tapschemamanager.businesslayer.TapSchema;
import java.io.Serializable;
Sonia Zorba
committed
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
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("tapSchemaEditing")
@ConversationScoped
public class TapSchemaEditingBean implements Serializable {
Sonia Zorba
committed
private static final long serialVersionUID = -6251004452688984277L;
@Inject
private Conversation conversation;
Sonia Zorba
committed
@Inject
SchemaSelectionBean schemaSelection;
Sonia Zorba
committed
private TapSchema tapSchema;
Sonia Zorba
committed
private EntityWrapperContainer currentAddingContainer;
private List<AddableItem> currentAddables;
@Inject
private SearchUCDDialog searchUCDDialog;
Sonia Zorba
committed
public static class AddableItem implements Serializable {
private static final long serialVersionUID = 2732253307571391962L;
private String name;
private boolean selected;
AddableItem() {
}
AddableItem(String name) {
this.name = name;
}
public String getName() {
return name;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
Sonia Zorba
committed
public TapSchema getTapSchema() {
return tapSchema;
}
Sonia Zorba
committed
public void setTapSchema(TapSchema tapSchema) {
this.tapSchema = tapSchema;
}
Sonia Zorba
committed
public SearchUCDDialog getSearchUCDDialog() {
return searchUCDDialog;
}
Sonia Zorba
committed
public String back() {
return "schemaSelection.xhtml?faces-redirect=true";
}
public String logout() {
conversation.end();
return "index.xhtml?faces-redirect=true";
}
Sonia Zorba
committed
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
194
195
196
public void undoRemove(EntityWrapperContainer ewc) {
ewc.getSelectedEntity().setStatus(Status.ADDED_PERSISTED);
}
public EntityWrapperContainer getCurrentAddingContainer() {
return currentAddingContainer;
}
public void openAddablesModal(EntityWrapperContainer<?> currentAddingContainer) {
this.currentAddingContainer = currentAddingContainer;
this.currentAddables = new ArrayList<AddableItem>();
for (String name : currentAddingContainer.getAddables()) {
currentAddables.add(new AddableItem(name));
}
}
public void checkAllEntities(boolean value) {
for (AddableItem item : currentAddables) {
item.setSelected(value);
}
}
public void addSelected() throws SQLException {
for (AddableItem item : currentAddables) {
if (item.isSelected()) {
currentAddingContainer.addEntityWrapper(item.getName());
}
}
}
public List<AddableItem> getCurrentAddables() {
return currentAddables;
}
public void saveUCD() {
tapSchema.getSelectedColumn().setUcd(searchUCDDialog.getSelectedUCD());
}
public void update() throws SQLException {
tapSchema.save();
}
static class InputChangeData {
String entity;
String key;
String value;
}
public void openUCDDialog() throws Exception {
searchUCDDialog.setDefault();
String description = tapSchema.getSelectedColumn().getDescription();
if (description != null && !description.equals("")) {
searchUCDDialog.setDescription(description);
searchUCDDialog.search(description);
}
}
private CustomPartialResponseWriter getCustomPartialResponseWriter() {
return (CustomPartialResponseWriter) FacesContext.getCurrentInstance().getPartialViewContext().getPartialResponseWriter();
}
private String getSourceComponentId() {
return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("javax.faces.source");
}
public void textInputChanged(EntityWrapper entityWrapper, String key) {
CustomPartialResponseWriter writer = getCustomPartialResponseWriter();
writer.addCustomUpdate(getSourceComponentId(), entityWrapper.isChanged(key) + "");
}
public void removeColumn(String name) {
tapSchema.getSelectedTable().removeEntityWrapper(name);
Column selectedColumn = tapSchema.getSelectedColumn();
Integer selectedColumnIndex = null;
if (selectedColumn != null) {
int index = 0;
for (String columnName : tapSchema.getSelectedTable().getEntitiesNames()) {
if (columnName.equals(selectedColumn.getName())) {
selectedColumnIndex = index;
break;
}
index++;
}
}
Column removedColumn = tapSchema.getSelectedTable().getEntity(name);
CustomPartialResponseWriter writer = getCustomPartialResponseWriter();
writer.addCustomUpdate(
getSourceComponentId(),
String.format("{\"selectedColumn\": %s,\"hideRemoved\": %s}", selectedColumnIndex, removedColumn.isHidden())
);
}
public void undoRemoveColumn() {
Table selectedTable = tapSchema.getSelectedTable();
this.undoRemove(selectedTable);
String selectedColumn = tapSchema.getSelectedColumn().getName();
int columnIndex = selectedTable.getEntitiesNames().indexOf(selectedColumn);
CustomPartialResponseWriter writer = getCustomPartialResponseWriter();
writer.addCustomUpdate(getSourceComponentId(), columnIndex + "");
}