diff --git a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/EntityWrapper.java b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/EntityWrapper.java index 76d76731a94ea25c0a78ed17143e309f03ef8804..c70b65a021deea7422e91820e7b08120d786bab3 100644 --- a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/EntityWrapper.java +++ b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/EntityWrapper.java @@ -1,6 +1,7 @@ package it.inaf.oats.ia2.tapschemamanager.businesslayer; import it.inaf.oats.ia2.tapschemamanager.datalayer.TapSchemaEntity; +import java.io.Serializable; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -11,22 +12,19 @@ import java.util.Map; * @author Sonia Zorba * @param */ -public abstract class EntityWrapper { +public abstract class EntityWrapper implements Serializable { - private T entity; + private static final long serialVersionUID = -8399058826120891216L; + + private final T entity; private final Map originalValues; private final Map editedValues; - private List supportedKeys; + private final List supportedKeys; private Status status; - // Only for deserialization - protected EntityWrapper() { + public EntityWrapper(T entity, String... supportedKeys) { originalValues = new HashMap(); editedValues = new HashMap(); - } - - public EntityWrapper(T entity, String... supportedKeys) { - this(); this.entity = entity; this.supportedKeys = Arrays.asList(supportedKeys); } @@ -102,11 +100,11 @@ public abstract class EntityWrapper { } editedValues.clear(); } - + protected void undoChanges() { editedValues.clear(); } - + public boolean isToRemove() { return status == Status.TO_REMOVE; } diff --git a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/Schema.java b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/Schema.java index 78186ee84337df9ceb194459c71873231e2a5120..f8836ca0bdaf4f5cf103199ea091df15a2effcbc 100644 --- a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/Schema.java +++ b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/Schema.java @@ -27,11 +27,6 @@ public class Schema extends EntityWrapper implements EntityWrapper private String selectedTable; private Map tables; - // Only for deserialization - protected Schema() { - super(); - } - public Schema(TapSchemaHandler tapSchemaHandler, SchemaEntity schemaEntity) throws SQLException { super(schemaEntity, UTYPE, DESCRIPTION); diff --git a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/Table.java b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/Table.java index a6fee8e3486aa280b51a7393a88bd8431dedb86e..1be645281d2befa4d0bd1f5b5cfd9d2827813edd 100644 --- a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/Table.java +++ b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/Table.java @@ -26,15 +26,9 @@ public class Table extends EntityWrapper implements EntityWrapperCo private String selectedColumn; private final Map columns; - private TapSchemaHandler tapSchemaHandler; - private String schemaName; - private String tableName; - - // Only for deserialization - protected Table() { - super(); - columns = new TreeMap(String.CASE_INSENSITIVE_ORDER); - } + private final TapSchemaHandler tapSchemaHandler; + private final String schemaName; + private final String tableName; public Table(TapSchemaHandler tapSchemaHandler, String schemaName, String tableName, TableEntity tableEntity) throws SQLException { super(tableEntity, UTYPE, DESCRIPTION); diff --git a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/TapSchema.java b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/TapSchema.java index 34c541e30597eec0cd794b09369d4dc4e8f2e848..dd5fac701a3d2f201840b0a882ade873486a3e4c 100644 --- a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/TapSchema.java +++ b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/businesslayer/TapSchema.java @@ -164,4 +164,8 @@ public class TapSchema implements EntityWrapperContainer, Serializable { public Schema getSelectedEntity() { return selectedSchema == null ? null : schemas.get(selectedSchema); } + + public TapSchemaHandler getTapSchemaHandler() { + return tapSchemaHandler; + } } diff --git a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/CredentialsBean.java b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/CredentialsBean.java index 617ee9b9e8b01813700ea7e6b1c9c1bd34d46ab5..4e53affa6b5bd4255477e2f5a6e6a329740ba50d 100644 --- a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/CredentialsBean.java +++ b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/CredentialsBean.java @@ -17,7 +17,7 @@ import javax.inject.Named; @Named("credentialsInsertion") @RequestScoped public class CredentialsBean implements Serializable { - + private static final long serialVersionUID = -2688980249773483198L; @Inject @@ -80,6 +80,7 @@ public class CredentialsBean implements Serializable { try { Connection connection = credentials.getConnection(); connection.close(); + conversation.setTimeout(30 * 60000L); // 30 minutes conversation.begin(); schemaSelectionBean.setCredentials(credentials); return "schemaSelection.xhtml?faces-redirect=true"; diff --git a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/CustomPartialResponseWriter.java b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/CustomPartialResponseWriter.java index 83253930d6114fd09ce54f097f92499c4ae1dee4..bc1c5df88638e6a71325026f818b150c857491cd 100644 --- a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/CustomPartialResponseWriter.java +++ b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/CustomPartialResponseWriter.java @@ -1,14 +1,15 @@ package it.inaf.oats.ia2.tapschemamanager.webapp; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; -import java.util.List; +import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; +import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.context.PartialResponseWriter; import javax.faces.context.ResponseWriter; -import javax.faces.event.AjaxBehaviorEvent; /** * @@ -16,48 +17,55 @@ import javax.faces.event.AjaxBehaviorEvent; */ public class CustomPartialResponseWriter extends PartialResponseWriter { - private static class JavascriptCustomUpdate { - - private final String componentId; - private final String value; - - JavascriptCustomUpdate(String componentId, String value) { - this.componentId = componentId; - this.value = value; - } - } - - private final List customUpdates; + private final Set componentsToEncode; + private final Map customJSUpdates; public CustomPartialResponseWriter(ResponseWriter wrapped) { super(wrapped); - customUpdates = new ArrayList(); - } - - public void addCustomUpdate(String componentId, String value) { - customUpdates.add(new JavascriptCustomUpdate(componentId, value)); - } - - public void addCustomUpdate(AjaxBehaviorEvent event, String value) { - this.addCustomUpdate(event.getComponent().getClientId(), value); + componentsToEncode = new HashSet(); + customJSUpdates = new HashMap(); } @Override public void endDocument() throws IOException { + FacesContext fctx = FacesContext.getCurrentInstance(); - Map params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); - for (Map.Entry entry : params.entrySet()) { - System.out.println(entry.getKey() + ": " + entry.getValue()); + if (!customJSUpdates.isEmpty()) { + startExtension(Collections.singletonMap("id", "jsupdates")); + for (Map.Entry entry : customJSUpdates.entrySet()) { + String componentId = entry.getKey(); + startElement("jsupdate", null); + writeAttribute("src", componentId, null); + write(entry.getValue().getUpdate()); + endElement("jsupdate"); + } + endExtension(); } - if (!customUpdates.isEmpty()) { - startExtension(Collections.singletonMap("id", "jsupdates")); - for (JavascriptCustomUpdate update : customUpdates) { - write(String.format("%s", update.componentId, update.value)); + if (!componentsToEncode.isEmpty()) { + startExtension(Collections.singletonMap("id", "htmlupdates")); + for (String componentId : componentsToEncode) { + UIComponent component = fctx.getViewRoot().findComponent(componentId); + startElement("htmlupdate", null); + writeAttribute("src", componentId, null); + component.encodeAll(fctx); + endElement("htmlupdate"); } endExtension(); } super.endDocument(); } + + public void encodeComponent(String componentId) { + componentsToEncode.add(componentId); + } + + public void addCustomJSUpdate(String componentId, JSUpdateHandler updateHandler) { + customJSUpdates.put(componentId, updateHandler); + } + + public static CustomPartialResponseWriter getCurrentInstance() { + return (CustomPartialResponseWriter) FacesContext.getCurrentInstance().getPartialViewContext().getPartialResponseWriter(); + } } diff --git a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/JSUpdateHandler.java b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/JSUpdateHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..c31a0e1e16fd318972811aef864bd32738876bd2 --- /dev/null +++ b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/JSUpdateHandler.java @@ -0,0 +1,10 @@ +package it.inaf.oats.ia2.tapschemamanager.webapp; + +/** + * + * @author Sonia Zorba + */ +public abstract class JSUpdateHandler { + + public abstract String getUpdate(); +} diff --git a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/TapSchemaEditingBean.java b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/TapSchemaEditingBean.java index 3946ef680c2fb550575de7203ec30539b6cb361c..379f2b78c6454e63634683ccfbb3641e54ee59aa 100644 --- a/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/TapSchemaEditingBean.java +++ b/TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/TapSchemaEditingBean.java @@ -10,11 +10,14 @@ import java.io.Serializable; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import javax.annotation.PreDestroy; import javax.enterprise.context.Conversation; import javax.enterprise.context.ConversationScoped; import javax.faces.context.FacesContext; import javax.inject.Inject; import javax.inject.Named; +import javax.json.Json; +import javax.json.JsonObjectBuilder; /** * @@ -23,79 +26,78 @@ import javax.inject.Named; @Named("tapSchemaEditing") @ConversationScoped public class TapSchemaEditingBean implements Serializable { - + private static final long serialVersionUID = -6251004452688984277L; - + + private static final String COLUMNS_COMPONENT_ID = "main:columns-list"; + @Inject private Conversation conversation; - + @Inject SchemaSelectionBean schemaSelection; - + private TapSchema tapSchema; - + private EntityWrapperContainer currentAddingContainer; private List currentAddables; - + @Inject private SearchUCDDialog searchUCDDialog; - + public static class AddableItem implements Serializable { - + private static final long serialVersionUID = 2732253307571391962L; - - private String name; + + private final 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; } } - + public TapSchema getTapSchema() { return tapSchema; } - + public void setTapSchema(TapSchema tapSchema) { this.tapSchema = tapSchema; } - + public SearchUCDDialog getSearchUCDDialog() { return searchUCDDialog; } - + public String back() { return "schemaSelection.xhtml?faces-redirect=true"; } - + public String logout() { conversation.end(); return "index.xhtml?faces-redirect=true"; } - + 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(); @@ -103,13 +105,13 @@ public class TapSchemaEditingBean implements Serializable { 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()) { @@ -117,26 +119,19 @@ public class TapSchemaEditingBean implements Serializable { } } } - + public List 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(); @@ -145,23 +140,23 @@ public class TapSchemaEditingBean implements Serializable { 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) + ""); + final boolean isChanged = entityWrapper.isChanged(key); + CustomPartialResponseWriter writer = CustomPartialResponseWriter.getCurrentInstance(); + String sourceComponentId = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("javax.faces.source"); + writer.addCustomJSUpdate(sourceComponentId, new JSUpdateHandler() { + + @Override + public String getUpdate() { + return isChanged + ""; + } + }); } - + public void removeColumn(String name) { tapSchema.getSelectedTable().removeEntityWrapper(name); - + Column selectedColumn = tapSchema.getSelectedColumn(); Integer selectedColumnIndex = null; if (selectedColumn != null) { @@ -174,24 +169,47 @@ public class TapSchemaEditingBean implements Serializable { index++; } } - + Column removedColumn = tapSchema.getSelectedTable().getEntity(name); - - CustomPartialResponseWriter writer = getCustomPartialResponseWriter(); - writer.addCustomUpdate( - getSourceComponentId(), - String.format("{\"selectedColumn\": %s,\"hideRemoved\": %s}", selectedColumnIndex, removedColumn.isHidden()) - ); - } - + + CustomPartialResponseWriter writer = CustomPartialResponseWriter.getCurrentInstance(); + + JsonObjectBuilder job = Json.createObjectBuilder(); + if (selectedColumnIndex != null) { + job.add("selectedColumn", selectedColumnIndex); + } + job.add("hideRemoved", removedColumn.isHidden()); + final String updateResult = job.build().toString(); + + writer.encodeComponent(COLUMNS_COMPONENT_ID); + writer.addCustomJSUpdate(COLUMNS_COMPONENT_ID, new JSUpdateHandler() { + + @Override + public String getUpdate() { + return updateResult; + } + }); + } + 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 + ""); + final int columnIndex = selectedTable.getEntitiesNames().indexOf(selectedColumn); + + CustomPartialResponseWriter writer = CustomPartialResponseWriter.getCurrentInstance(); + writer.addCustomJSUpdate(COLUMNS_COMPONENT_ID, new JSUpdateHandler() { + + @Override + public String getUpdate() { + return columnIndex + ""; + } + }); + } + + @PreDestroy + public void onDestroy() { + tapSchema.getTapSchemaHandler().onDestroy(); } } diff --git a/TapSchemaManager/src/main/webapp/WEB-INF/web.xml b/TapSchemaManager/src/main/webapp/WEB-INF/web.xml index c562314e60fea8fee1045e19df442b600313d2d3..dae5711a4944189f2736619cc16367a96641ef4d 100644 --- a/TapSchemaManager/src/main/webapp/WEB-INF/web.xml +++ b/TapSchemaManager/src/main/webapp/WEB-INF/web.xml @@ -57,4 +57,8 @@ faces/index.xhtml + + org.jboss.weld.context.NonexistentConversationException + /faces/expired.xhtml?nocid=true + diff --git a/TapSchemaManager/src/main/webapp/expired.xhtml b/TapSchemaManager/src/main/webapp/expired.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..4f96788436a707d8719cdecc5ae26c86c23eee49 --- /dev/null +++ b/TapSchemaManager/src/main/webapp/expired.xhtml @@ -0,0 +1,23 @@ + + + TapSchema Manager - Credentials insertion page + + +
+
+
+
+
+ + Your session has expired. Please log in again. +
+
+
+
+
+
+
\ No newline at end of file diff --git a/TapSchemaManager/src/main/webapp/resources/js/edit-tapschema.js b/TapSchemaManager/src/main/webapp/resources/js/edit-tapschema.js index 488d90073b65d15dbd7b26d03e51e6bb58fca973..cfda5da23ca5b987df07a190b2c8aba2ca746ec1 100644 --- a/TapSchemaManager/src/main/webapp/resources/js/edit-tapschema.js +++ b/TapSchemaManager/src/main/webapp/resources/js/edit-tapschema.js @@ -1,27 +1,46 @@ (function ($) { - function eventHandlerFactory(handler) { + // Function factory to handle custom communications between the backing bean and JavaScript functions + function eventHandlerFactory(handler, componentId) { return function (event) { if (event.status === 'success') { + var srcId = componentId ? componentId : event.source.getAttribute('id'); + var jsUpdate = null, htmlUpdate = null; + var jsupdates = event.responseXML.getElementById('jsupdates'); if (jsupdates) { jsupdates = jsupdates.childNodes; - var sourceId = event.source.getAttribute('id'); for (var i = 0; i < jsupdates.length; i++) { - var jsupdate = jsupdates[i]; - if (jsupdate.getAttribute('src') === sourceId) { - handler(event.source, jsupdate.innerText || jsupdate.textContent); - return; + var jsu = jsupdates[i]; + if (jsu.getAttribute('src') === srcId) { + jsUpdate = jsu.innerText || jsu.textContent; + break; + } + } + } + + var htmlupdates = event.responseXML.getElementById('htmlupdates'); + if (htmlupdates) { + htmlupdates = htmlupdates.childNodes; + for (var i = 0; i < htmlupdates.length; i++) { + var hu = htmlupdates[i]; + if (hu.getAttribute('src') === srcId) { + htmlUpdate = hu; + break; } } } + + handler(event.source, jsUpdate, htmlUpdate); } }; } - window.global = { - textInputChanged: eventHandlerFactory(function (srcElement, response) { - $(srcElement).toggleClass('changed', response === 'true'); + var COLUMNS_COMPONENT_ID = 'main:columns-list'; + + window.TSM = { + textInputChanged: eventHandlerFactory(function (srcElement, jsupdate) { + $(srcElement).toggleClass('changed', jsupdate === 'true'); }), columnChanged: function (event) { if (event.status === 'success') { @@ -35,34 +54,41 @@ event.preventDefault(); return false; }, - columnRemoved: eventHandlerFactory(function (srcElement, response) { - response = JSON.parse(response); + columnRemoved: eventHandlerFactory(function (srcElement, jsupdate, htmlupdate) { + jsupdate = JSON.parse(jsupdate); var $ul = $(srcElement).closest('ul'); - if (response.hideRemoved) { + if (jsupdate.hideRemoved) { $(srcElement).closest('li').remove(); } else { $(srcElement).closest('a').find('span').addClass('strikeout'); $(srcElement).prop('disabled', true); } - if (response.selectedColumn !== null) { + if (jsupdate.selectedColumn !== undefined) { $ul.find('li').removeClass('active'); - $ul.find('li:nth-child(' + (response.selectedColumn + 1) + ')').addClass('active'); + $ul.find('li:nth-child(' + (jsupdate.selectedColumn + 1) + ')').addClass('active'); } - if (response.hideRemoved) { + if (jsupdate.hideRemoved) { // Restore correct ids - $ul.find('li').each(function (index, element) { - var $a = $(element).find('a'); - var baseId = 'main:columns-list:' + index; - $a.attr('id', baseId + ':column-selector'); - $a.find('input').attr('id', baseId + ':column-remover'); + $htmlUpdate = $(htmlupdate); + $htmlUpdate.find('li a'); + $htmlUpdate.find('li a input'); + + $htmlUpdate.find('li').each(function (index, element) { + var $this = $(element); + var $input = $this.find('input'); + + var $li = $('.columns-selector').find('li:nth-child(' + (index + 1) + ')'); + $li.attr('id', $this.attr('id')); + $li.find('a').attr('id', $this.find('a').attr('id')); + $li.find('input').attr('id', $input.attr('id')).attr('name', $input.attr('name')); }); } - }), - columnRemovalUndo: eventHandlerFactory(function (srcElement, response) { - var $a = $('#main\\:columns-list\\:' + response + '\\:column-selector'); + }, COLUMNS_COMPONENT_ID), + columnRemovalUndo: eventHandlerFactory(function (srcElement, jsupdate) { + var $a = $('#main\\:columns-list\\:' + jsupdate + '\\:column-selector'); $a.find('input').prop('disabled', false); $a.find('.strikeout').removeClass('strikeout'); - }), + }, COLUMNS_COMPONENT_ID), ucdTextKeyDown: function (event) { if (event.keyCode === 13) { $('#ucd_search_form\\:search_UCD_btn').click(); @@ -87,7 +113,25 @@ if (event.status === 'success') { $('#searchUCDModal').modal('hide'); } + }, + notifyUpdate: function (event) { + if (event.status === 'success' && $(event.responseXML).find('error').length === 0) { + $('#updateSuccessModal').modal('show'); + } } }; + $(document).ready(function () { + jsf.ajax.addOnError(function (error) { + $('#errorModal .errorName').text(error.errorName); + $('#errorModal .errorMessage').text(error.errorMessage); + if (error.errorName.indexOf('NonexistentConversationException') !== -1) { + // If conversation has expired reload the page to display error message + location.reload(); + } else { + $('#errorModal').modal('show'); + } + }); + }); + })(jQuery); \ No newline at end of file diff --git a/TapSchemaManager/src/main/webapp/tapSchemaEditing.xhtml b/TapSchemaManager/src/main/webapp/tapSchemaEditing.xhtml index ba05289bdce61c737d1c13847534376a11c30f66..9531b7d3780445afa0c2c5b7fb6005aca5d3d48e 100644 --- a/TapSchemaManager/src/main/webapp/tapSchemaEditing.xhtml +++ b/TapSchemaManager/src/main/webapp/tapSchemaEditing.xhtml @@ -20,7 +20,7 @@ Update - +
@@ -45,7 +45,7 @@ #{schema.name} - + @@ -55,7 +55,7 @@
  • - +
  • @@ -85,7 +85,7 @@ id="schema_utype" class="form-control #{tapSchema.selectedEntity.isChanged('utype') ? 'changed' : ''}" value="#{tapSchema.selectedEntity.utype}"> - +
    @@ -96,7 +96,7 @@ id="schema_description" class="form-control #{tapSchema.selectedEntity.isChanged('description') ? 'changed' : ''}" value="#{tapSchema.selectedEntity.description}"> - + @@ -110,7 +110,7 @@ #{table.name} - + @@ -120,7 +120,7 @@
  • - +
  • @@ -151,7 +151,7 @@ id="table_utype" class="form-control #{tapSchema.selectedTable.isChanged('utype') ? 'changed' : ''}" value="#{tapSchema.selectedTable.utype}"> - + @@ -162,7 +162,7 @@ id="table_description" class="form-control #{tapSchema.selectedTable.isChanged('description') ? 'changed' : ''}" value="#{tapSchema.selectedTable.description}"> - + @@ -174,7 +174,7 @@ Columns - + @@ -196,8 +196,8 @@ @@ -225,7 +225,7 @@ This column will be removed on TAP Schema Update. Undo - + @@ -277,14 +277,14 @@ id="column_utype" class="form-control #{tapSchema.selectedColumn.isChanged('utype') ? 'changed' : ''}" value="#{tapSchema.selectedColumn.utype}"> - +
    #{tapSchemaEditing.tapSchema.selectedColumn.ucd} - +
    @@ -293,7 +293,7 @@ id="column_unit" class="form-control #{tapSchema.selectedColumn.isChanged('unit') ? 'changed' : ''}" value="#{tapSchema.selectedColumn.unit}"> - +
    @@ -302,7 +302,7 @@ id="column_description" class="form-control #{tapSchema.selectedColumn.isChanged('description') ? 'changed' : ''}" value="#{tapSchema.selectedColumn.description}"> - +
    @@ -360,7 +360,7 @@ Add - + @@ -383,9 +383,7 @@
    Description:
    - - - + @@ -441,7 +439,7 @@ @@ -449,5 +447,48 @@
    + + + + \ No newline at end of file diff --git a/TapSchemaManagerDL/pom.xml b/TapSchemaManagerDL/pom.xml index fc42a1d4041a3c9bc0c62bc8d97f5137e0221b5c..c5976196ec551eeee77eefbe1cb62a4e4fc6d2aa 100644 --- a/TapSchemaManagerDL/pom.xml +++ b/TapSchemaManagerDL/pom.xml @@ -14,7 +14,7 @@ org.eclipse.persistence eclipselink - 2.5.2 + 2.6.2 mysql diff --git a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/ColumnEntity.java b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/ColumnEntity.java index 8992a2d19a731733bca88d51d47368d0cfbf3c62..eb977e0f4abd9d78593ebbd70bc53f21743a028c 100644 --- a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/ColumnEntity.java +++ b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/ColumnEntity.java @@ -13,6 +13,8 @@ import javax.persistence.Table; class ColumnId implements Serializable { + private static final long serialVersionUID = 6943729649657196881L; + String fullTableName; String name; } @@ -26,6 +28,8 @@ class ColumnId implements Serializable { @Table(name = "columns") public class ColumnEntity implements Serializable, TapSchemaEntity { + private static final long serialVersionUID = 3630294743516824359L; + @Id @Column(name = "table_name", length = 128) private String fullTableName; @@ -176,7 +180,7 @@ public class ColumnEntity implements Serializable, TapSchemaEntity { public TableEntity getTable() { return table; } - + protected void setTable(TableEntity tableEntity) { this.table = tableEntity; } diff --git a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/ColumnInfo.java b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/ColumnInfo.java index 7be8577b141da354f24f6d0949fb2134ea03bed5..6c263b1a93319b11c8eecb444e70f043267b8558 100644 --- a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/ColumnInfo.java +++ b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/ColumnInfo.java @@ -8,6 +8,8 @@ import java.io.Serializable; */ public class ColumnInfo implements Serializable { + private static final long serialVersionUID = 2139630525057375743L; + private boolean primaryKey; private final ColumnEntity columnEntity; diff --git a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/Credentials.java b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/Credentials.java index 3ed82c7518e2c15453157e83e66248b0dfa6aeca..ae51720573eaaf693f473cdde45356de7a0470ab 100644 --- a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/Credentials.java +++ b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/Credentials.java @@ -10,7 +10,9 @@ import java.sql.SQLException; * @author Sonia Zorba */ public class Credentials implements Serializable { - + + private static final long serialVersionUID = 1153912575502196261L; + private String hostname; private int port; private String username; diff --git a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/KeyColumnEntity.java b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/KeyColumnEntity.java index 5790c03a58fa1cd6259bc0dc67f6f4781355e3b6..5933f208ec2d95efe9a93b179926a7a260e3db35 100644 --- a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/KeyColumnEntity.java +++ b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/KeyColumnEntity.java @@ -12,6 +12,8 @@ import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Table; class KeyColumn implements Serializable { + + private static final long serialVersionUID = 1244476100879775193L; String keyId; String fromColumn; @@ -26,6 +28,8 @@ class KeyColumn implements Serializable { @IdClass(KeyColumn.class) @Table(name = "key_columns") public class KeyColumnEntity implements Serializable { + + private static final long serialVersionUID = -1841850907719547336L; @Id @Column(name = "key_id", length = 64) diff --git a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/KeyEntity.java b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/KeyEntity.java index 375eae401aad763373190b73704dc6be727901e2..d0b7e5e8a692fc833e0f6e2f77b38252933acd65 100644 --- a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/KeyEntity.java +++ b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/KeyEntity.java @@ -21,6 +21,8 @@ import javax.persistence.Table; @Entity @Table(name = "`keys`") public class KeyEntity implements Serializable { + + private static final long serialVersionUID = 4321901642780866919L; @Id @Column(name = "key_id", length = 64) @@ -128,19 +130,4 @@ public class KeyEntity implements Serializable { public List getKeyColumns() { return keyColumns; } - - @Override - public boolean equals(Object obj) { - if (obj.getClass() != KeyEntity.class) { - return false; - } - return ((KeyEntity) obj).getKeyId().equals(this.getKeyId()); - } - - @Override - public int hashCode() { - int hash = 7; - hash = 97 * hash + (this.keyId != null ? this.keyId.hashCode() : 0); - return hash; - } } diff --git a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/SchemaEntity.java b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/SchemaEntity.java index 06eea6ba52600d1b10807916287da49cccb4cd0c..8d61b66840a50b9171bcc7c29a6a136c632b9387 100644 --- a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/SchemaEntity.java +++ b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/SchemaEntity.java @@ -22,6 +22,8 @@ import javax.persistence.Table; @Table(name = "`schemas`") public class SchemaEntity implements Serializable, TapSchemaEntity { + private static final long serialVersionUID = -1058919664128696098L; + @Id @Column(name = "schema_name", length = 64) private String name; diff --git a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/TableEntity.java b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/TableEntity.java index ab0344c93ae85aa09fa2e391a2774aafd1b5859e..580e0e23493680dbe1e1f48e9a1a6f26bae89733 100644 --- a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/TableEntity.java +++ b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/TableEntity.java @@ -26,6 +26,8 @@ import javax.persistence.Table; @Table(name = "tables") public class TableEntity implements Serializable, TapSchemaEntity { + private static final long serialVersionUID = 5386350231967268073L; + @Id @Column(name = "table_name", length = 128) private String name; @@ -54,10 +56,10 @@ public class TableEntity implements Serializable, TapSchemaEntity { @OrderBy("name ASC") private final List columns; - @OneToMany(mappedBy = "fromTable", cascade = CascadeType.ALL, orphanRemoval = true) + @OneToMany(mappedBy = "fromTable", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) private final List fromKeys; - @OneToMany(mappedBy = "targetTable", cascade = CascadeType.ALL, orphanRemoval = true) + @OneToMany(mappedBy = "targetTable", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) private final List targetKeys; protected TableEntity() { @@ -176,7 +178,6 @@ public class TableEntity implements Serializable, TapSchemaEntity { // } // return false; // } - public void addFromKey(KeyEntity key) { if (!fromKeys.contains(key)) { fromKeys.add(key); diff --git a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/TapSchemaHandler.java b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/TapSchemaHandler.java index 21dccfc3949c7056f3f8f047d47e7c9b08c6a22a..4ceb16eadf9fb56ccd5afa1f7b613395d86f835d 100644 --- a/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/TapSchemaHandler.java +++ b/TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/TapSchemaHandler.java @@ -9,11 +9,12 @@ import java.util.List; import java.util.Map; import java.util.regex.Pattern; import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; class SchemaInfo implements Serializable { - + private static final long serialVersionUID = 2835388936102349727L; private final List allSchemaTables; @@ -40,7 +41,7 @@ class SchemaInfo implements Serializable { } class ColumnsInfo implements Serializable { - + private static final long serialVersionUID = -3407052226160044192L; private final Map>> columnsInfo; @@ -69,7 +70,7 @@ class ColumnsInfo implements Serializable { * @author Sonia Zorba */ public class TapSchemaHandler implements Serializable { - + private static final long serialVersionUID = 1193743698810532785L; private final Credentials credentials; @@ -108,7 +109,7 @@ public class TapSchemaHandler implements Serializable { this.columnsInfo = new ColumnsInfo(); if (exists) { - entityManager = DataProvider.getEntityManager(credentials, tapSchemaName); + loadEntityManager(); CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(SchemaEntity.class); for (SchemaEntity schemaEntity : entityManager.createQuery(cq).getResultList()) { @@ -197,7 +198,7 @@ public class TapSchemaHandler implements Serializable { TableEntity table = new TableEntity(getSchema(schemaName), shortTableName); table.setTableType(allSchemaInfos.get(schemaName).getTablesType().get(shortTableName)); - + Connection conn = getConnection(); try { // Add columns info @@ -310,6 +311,8 @@ public class TapSchemaHandler implements Serializable { public void save() throws SQLException { if (exists) { + loadEntityManager(); + entityManager.getTransaction().begin(); for (SchemaEntity toRemoveSchema : toRemoveSchemas) { entityManager.remove(toRemoveSchema); @@ -326,7 +329,8 @@ public class TapSchemaHandler implements Serializable { } finally { closeConnection(); } - entityManager = DataProvider.getEntityManager(credentials, name); + + loadEntityManager(); entityManager.getTransaction().begin(); for (SchemaEntity schemaEntity : schemas) { @@ -355,4 +359,21 @@ public class TapSchemaHandler implements Serializable { exists = true; } } + + private void loadEntityManager() { + if(entityManager == null) { + entityManager = DataProvider.getEntityManager(credentials, name); + } + } + + public void onDestroy() { + EntityManagerFactory efFactory = entityManager.getEntityManagerFactory(); + entityManager.close(); + efFactory.close(); + try { + closeConnection(); + } catch (SQLException e) { + e.printStackTrace(System.err); + } + } }