Skip to content
Snippets Groups Projects
Commit 480e5518 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added modal for keys editing, various improvements and fixes

parent cda98f33
No related branches found
No related tags found
No related merge requests found
Showing with 236 additions and 28 deletions
......@@ -306,4 +306,38 @@ public class TSMUtil {
return sb.toString();
}
/**
* Utility class for joining a collection of object properties.
*/
public static class StringJoiner<T> {
private final Iterable<T> values;
private final String separator;
public StringJoiner(Iterable<T> values, String separator) {
this.values = values;
this.separator = separator;
}
public final String getString() {
StringBuilder sb = new StringBuilder();
boolean first = true;
for (T value : values) {
if (!first) {
sb.append(separator);
}
sb.append(getStringValue(value));
first = false;
}
return sb.toString();
}
public String getStringValue(T value) {
if (value instanceof String) {
return (String) value;
}
return null;
}
}
}
......@@ -463,7 +463,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
if (obscore) {
SchemaModel ivoaSchemaModel = getIvoaSchemaModel();
broker.createIvoaSchemaStructure(ivoaSchemaModel);
// ivoa schema has to be created into source database
getSourceDBBroker().createIvoaSchemaStructure(ivoaSchemaModel);
// Initializing ivoa schema slot in schemata maps
schemas.put(ivoaSchemaModel.getName(), null);
......
......@@ -74,7 +74,11 @@ public class MySQLDBBroker extends DBBrokerTemplate {
if (beginIndex != -1) {
int endIndex = typeWithSize.indexOf(')');
if (endIndex != -1) {
try {
return Integer.parseInt(typeWithSize.substring(beginIndex + 1, endIndex));
} catch (NumberFormatException e) {
return null;
}
}
}
return null;
......
......@@ -107,6 +107,9 @@ public class SearchUCDDialog implements Serializable {
String assignResponse = SearchUCD.assign(description);
if (assignResponse == null) {
UCDnotFound = true;
selectedUCD = null;
suggestedUCD = null;
suggestedUCDs.clear();
} else {
selectedUCD = assignResponse;
suggestedUCD = assignResponse;
......
......@@ -30,6 +30,7 @@ import it.inaf.ia2.tsm.Key;
import it.inaf.ia2.tsm.KeyColumn;
import it.inaf.ia2.tsm.Schema;
import it.inaf.ia2.tsm.Status;
import it.inaf.ia2.tsm.TSMUtil;
import it.inaf.ia2.tsm.Table;
import it.inaf.ia2.tsm.TapSchema;
import it.inaf.ia2.tsm.TapSchemaEntity;
......@@ -67,6 +68,7 @@ public class TapSchemaEditingBean implements Serializable {
private EntitiesContainer currentAddingContainer;
private List<AddableItem> currentAddables;
private boolean addAlsoAllChildren;
private VOUnitValidator voUnitValidator;
@Inject
......@@ -259,6 +261,7 @@ public class TapSchemaEditingBean implements Serializable {
}
public void openAddablesModal(EntitiesContainer<?> currentAddingContainer) {
this.addAlsoAllChildren = false;
this.currentAddingContainer = currentAddingContainer;
this.currentAddables = new ArrayList<>();
for (String name : currentAddingContainer.getAddableChildrenNames()) {
......@@ -277,11 +280,30 @@ public class TapSchemaEditingBean implements Serializable {
}
}
private void addAllChildren(TapSchemaEntity childEntity) throws SQLException {
if (childEntity instanceof Schema) {
Schema schema = (Schema) childEntity;
for (String tableName : schema.getAddableChildrenNames()) {
Table table = schema.addChild(tableName);
addAllChildren(table);
}
} else if (childEntity instanceof Table) {
Table table = (Table) childEntity;
for (String column : table.getAddableChildrenNames()) {
table.addChild(column);
}
}
}
public void addSelected() throws SQLException {
TapSchemaEntity lastAddedEntity = null;
boolean canAddChildren = isCanAddChildren();
for (AddableItem item : currentAddables) {
if (item.isSelected()) {
lastAddedEntity = currentAddingContainer.addChild(item.getName());
if (lastAddedEntity != null && canAddChildren) {
addAllChildren(lastAddedEntity);
}
}
}
if (lastAddedEntity != null) {
......@@ -299,6 +321,22 @@ public class TapSchemaEditingBean implements Serializable {
return currentAddables;
}
public boolean isCanAddChildren() {
if (currentAddingContainer == null) {
return false;
}
return currentAddingContainer instanceof TapSchema
|| currentAddingContainer instanceof Schema;
}
public boolean isAddAlsoAllChildren() {
return addAlsoAllChildren;
}
public void setAddAlsoAllChildren(boolean addAlsoAllChildren) {
this.addAlsoAllChildren = addAlsoAllChildren;
}
public void saveUCD() {
if (!FacesContext.getCurrentInstance().isValidationFailed()) {
......@@ -402,4 +440,32 @@ public class TapSchemaEditingBean implements Serializable {
column.setValue("principal", value ? 1 : 0);
}
}
public List<Key> getVisibleKeys() {
List<Key> keys = new ArrayList<>();
for (Key key : tapSchema.getAllKeys()) {
if (key.isVisible()) {
keys.add(key);
}
}
return keys;
}
public String formatFromColumns(Key key) {
return (new TSMUtil.StringJoiner<KeyColumn>(key.getKeyColumns(), ", ") {
@Override
public String getStringValue(KeyColumn kc) {
return kc.getFromColumn();
}
}).getString();
}
public String formatTargetColumns(Key key) {
return (new TSMUtil.StringJoiner<KeyColumn>(key.getKeyColumns(), ", ") {
@Override
public String getStringValue(KeyColumn kc) {
return kc.getTargetColumn();
}
}).getString();
}
}
......@@ -6,7 +6,6 @@ import it.inaf.ia2.tsm.webapp.xmlconfig.UCDConfiguration;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.deltaspike.core.api.scope.WindowScoped;
......@@ -76,11 +75,20 @@ public class UCDEditor implements Serializable {
invalidUCDMessage = "Invalid UCD word syntax";
return;
}
//
// newUCDConfiguration = new UCDConfiguration(user.getUsername());
// if(config.addUCD(newUCDConfiguration)) {
// ne
// }
if (!newUCDConfiguration.getWord().contains(":")) {
invalidUCDMessage = "Custom UCDs must have a namespace";
return;
}
boolean inserted = config.addUCD(newUCDConfiguration);
if (!inserted) {
invalidUCDMessage = "Specified UCD already exists";
return;
}
newUCDConfiguration = new UCDConfiguration(user.getUsername());
invalidUCDMessage = null;
}
public void removeUCD(UCDConfiguration ucd) {
......
......@@ -4,6 +4,10 @@
$('#updateOperationsModal').modal('show');
});
TSM.displayKeysModal = TSM.eventHandlerFactory(function (srcElement, jsupdate) {
$('#keysModal').modal('show');
});
TSM.saveUCDCalled = TSM.eventHandlerFactory(function (srcElement, jsupdate) {
if (jsupdate !== null) {
$('#searchUCDModal').modal('hide');
......
......@@ -31,12 +31,12 @@
<ul>
<ui:repeat value="#{ucdEditor.customUCDs}" var="ucd" varStatus="loop">
<li>
<h:commandLink class="text-danger" action="#{ucdEditor.removeUCD(ucd)}">
<h:commandLink class="text-danger" action="#{ucdEditor.removeUCD(ucd)}" rendered="#{ucdEditor.isEditable(ucd)}">
&#215;
<ui:remove>
<!-- Note: due to a strange JSF bug following render attribute needs complete component id reference -->
</ui:remove>
<f:ajax execute="ucd-editor-body" render="main:ucd-editor:ucd-editor-body" />
<f:ajax execute="ucd-editor-body" render=":main:ucd-editor:ucd-editor-body" />
</h:commandLink>
[#{ucd.code}] <span title="#{ucd.description}">#{ucd.word}</span>
</li>
......
......@@ -25,11 +25,31 @@
</h1>
<div class="col-sm-6 vpadding text-center">
<h:commandLink class="btn btn-info" action="#{tapSchemaEditing.displayUpdateOperations()}">
<div class="btn-group">
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-info-sign"></span>
Display update operations
Show <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
<h:commandLink action="#{tapSchemaEditing.displayUpdateOperations()}">
<span class="glyphicon glyphicon-cog"></span>
Update operations
<f:ajax execute="@form" render="update-operations-form" onevent="TSM.displayUpdateOperations"/>
</h:commandLink>
</li>
<li>
<h:commandLink>
<span class="icon-key"></span>
Keys
<ui:remove>
<!-- Very important: execute="@this", otherwise wrong values will be updated -->
</ui:remove>
<f:ajax execute="@this" render="keys-panel" onevent="TSM.displayKeysModal"/>
</h:commandLink>
</li>
</ul>
</div>
&#160;
<h:commandLink class="btn btn-success" action="#{tapSchemaEditing.update()}" id="update-btn">
<span class="icon-save"></span>
......@@ -366,6 +386,16 @@
<f:ajax event="keyup" execute="@form" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedColumn, 'description')}" onevent="TSM.textInputChanged" />
</h:inputText>
</div>
<h:panelGroup class="form-group" layout="block" rendered="#{tapSchemaEditing.selectedColumn.getProperty('xtype') ne null}">
<h:outputLabel for="column_xtype" class="control-label">Xtype:</h:outputLabel>
<h:inputText
id="column_xtype"
class="form-control #{tapSchemaEditing.selectedColumn.isChanged('xtype') ? 'changed' : ''}"
value="#{tapSchemaEditing.selectedColumn.getProperty('xtype').value}">
<f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" />
<f:ajax event="keyup" execute="@form" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedColumn, 'xtype')}" onevent="TSM.textInputChanged" />
</h:inputText>
</h:panelGroup>
</h:panelGroup>
</h:panelGroup>
</h:panelGroup>
......@@ -380,7 +410,7 @@
<div class="modal fade" tabindex="-1" role="dialog" id="addablesModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<h:panelGroup class="modal-content" id="addables_modal_content" layout="block">
<div class="modal-header">
<div class="pull-right">
<h:commandLink class="btn btn-default btn-sm" action="#{tapSchemaEditing.checkAllEntities(false)}">
......@@ -400,7 +430,6 @@
</div>
<div class="modal-body">
<div class="addables">
<h:panelGroup id="addables_modal_content">
<h:panelGroup rendered="#{tapSchemaEditing.currentAddingContainer ne null}">
<ui:repeat value="#{tapSchemaEditing.currentAddables}" var="item">
<div class="checkbox">
......@@ -411,16 +440,75 @@
</div>
</ui:repeat>
</h:panelGroup>
</h:panelGroup>
</div>
</div>
<div class="modal-footer">
<h:panelGroup class="checkbox pull-left" layout="block" rendered="#{tapSchemaEditing.canAddChildren}">
<label>
<h:selectBooleanCheckbox value="#{tapSchemaEditing.addAlsoAllChildren}" /> Add also all children
</label>
</h:panelGroup>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<h:commandLink class="btn btn-primary" action="#{tapSchemaEditing.addSelected}">
Add
<f:ajax execute="@form" render=":main:main_panel" onevent="TSM.entitiesAdded" />
</h:commandLink>
</div>
</h:panelGroup>
</div>
</div>
<div class="modal fade" tabindex="-1" role="dialog" id="keysModal">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&#215;</span></button>
<h4 class="modal-title">Keys</h4>
</div>
<h:panelGroup class="modal-body" layout="block" id="keys-panel">
<table class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>From table</th>
<th>From columns</th>
<th>Target table</th>
<th>Target columns</th>
<th>Utype</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<ui:repeat value="#{tapSchemaEditing.visibleKeys}" var="key">
<tr>
<td>#{key.id}</td>
<td>#{key.fromTableCompleteName}</td>
<td>#{tapSchemaEditing.formatFromColumns(key)}</td>
<td>#{key.targetTableCompleteName}</td>
<td>#{tapSchemaEditing.formatTargetColumns(key)}</td>
<td>
<h:inputText
id="key_utype"
class="form-control #{key.isChanged('utype') ? 'changed' : ''}"
value="#{key.getProperty('utype').value}">
<f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" />
<f:ajax event="keyup" execute="@form" listener="#{tapSchemaEditing.textInputChanged(key, 'utype')}" onevent="TSM.textInputChanged" />
</h:inputText>
</td>
<td>
<h:inputText
id="key_description"
class="form-control #{key.isChanged('description') ? 'changed' : ''}"
value="#{key.getProperty('description').value}">
<f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" />
<f:ajax event="keyup" execute="@form" listener="#{tapSchemaEditing.textInputChanged(key, 'description')}" onevent="TSM.textInputChanged" />
</h:inputText>
</td>
</tr>
</ui:repeat>
</tbody>
</table>
</h:panelGroup>
</div>
</div>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment