From 3834c27c8fab680ab532359db50e2d269133afe9 Mon Sep 17 00:00:00 2001 From: TonyO Date: Sat, 24 Mar 2018 22:33:41 -0500 Subject: [PATCH] SQL Export Code Commit --- .../refine/exporters/ExporterRegistry.java | 4 + .../exporters/sql/SqlCreateBuilder.java | 130 ++++++ .../google/refine/exporters/sql/SqlData.java | 61 +++ .../refine/exporters/sql/SqlExporter.java | 159 +++++++ .../exporters/sql/SqlInsertBuilder.java | 151 +++++++ .../tests/exporters/sql/SqlExporterTests.java | 304 +++++++++++++ .../webapp/modules/core/MOD-INF/controller.js | 3 +- .../modules/core/langs/translation-en.json | 11 +- .../scripts/dialogs/sql-exporter-dialog.html | 110 +++++ .../scripts/dialogs/sql-exporter-dialog.js | 408 ++++++++++++++++++ .../modules/core/scripts/project/exporters.js | 6 + .../styles/dialogs/sql-exporter-dialog.less | 94 ++++ 12 files changed, 1438 insertions(+), 3 deletions(-) create mode 100755 main/src/com/google/refine/exporters/sql/SqlCreateBuilder.java create mode 100755 main/src/com/google/refine/exporters/sql/SqlData.java create mode 100755 main/src/com/google/refine/exporters/sql/SqlExporter.java create mode 100755 main/src/com/google/refine/exporters/sql/SqlInsertBuilder.java create mode 100644 main/tests/server/src/com/google/refine/tests/exporters/sql/SqlExporterTests.java create mode 100755 main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.html create mode 100755 main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.js create mode 100644 main/webapp/modules/core/styles/dialogs/sql-exporter-dialog.less diff --git a/main/src/com/google/refine/exporters/ExporterRegistry.java b/main/src/com/google/refine/exporters/ExporterRegistry.java index a8f321157..69bc92103 100644 --- a/main/src/com/google/refine/exporters/ExporterRegistry.java +++ b/main/src/com/google/refine/exporters/ExporterRegistry.java @@ -36,6 +36,8 @@ package com.google.refine.exporters; import java.util.HashMap; import java.util.Map; +import com.google.refine.exporters.sql.SqlExporter; + abstract public class ExporterRegistry { static final private Map s_formatToExporter = new HashMap(); @@ -52,6 +54,8 @@ abstract public class ExporterRegistry { s_formatToExporter.put("html", new HtmlTableExporter()); s_formatToExporter.put("template", new TemplatingExporter()); + + s_formatToExporter.put("sql", new SqlExporter()); } static public void registerExporter(String format, Exporter exporter) { diff --git a/main/src/com/google/refine/exporters/sql/SqlCreateBuilder.java b/main/src/com/google/refine/exporters/sql/SqlCreateBuilder.java new file mode 100755 index 000000000..588b208ba --- /dev/null +++ b/main/src/com/google/refine/exporters/sql/SqlCreateBuilder.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2018, Tony Opara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of Google nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.google.refine.exporters.sql; + +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.refine.util.JSONUtilities; + +public class SqlCreateBuilder { + + private final static Logger logger = LoggerFactory.getLogger("SqlCreateBuilder"); + + private String table; + + @SuppressWarnings("unused") + private List columns; + + private JSONObject options; + + public SqlCreateBuilder(String table, List columns, JSONObject options) { + this.table = table; + this.columns = columns; + this.options = options; + } + + public String getCreateSQL() { + StringBuffer createSB = new StringBuffer(); + + JSONArray columnOptionArray = options == null ? null : JSONUtilities.getArray(options, "columns"); + + int count = columnOptionArray.length(); + + for (int i = 0; i < count; i++) { + JSONObject columnOptions = JSONUtilities.getObjectElement(columnOptionArray, i); + if (columnOptions != null) { + String name = JSONUtilities.getString(columnOptions, "name", null); + String type = JSONUtilities.getString(columnOptions, "type", "VARCHAR"); + String size = JSONUtilities.getString(columnOptions, "size", ""); + if (name != null) { + createSB.append(name + " "); + + if (type.equals("VARCHAR")) { + if (size.isEmpty()) { + size = "255"; + } + createSB.append(type + "(" + size + ")"); + + } else if (type.equals("CHAR")) { + if (size.isEmpty()) { + size = "10"; + } + createSB.append(type + "(" + size + ")"); + + } else if (type.equals("INT") || type.equals("INTEGER")) { + if (size.isEmpty()) { + createSB.append(type); + } else { + createSB.append(type + "(" + size + ")"); + } + + } else if (type.equals("NUMERIC")) { + if (size.isEmpty()) { + createSB.append(type); + } else { + createSB.append(type + "(" + size + ")"); + } + } else { + createSB.append(type); + } + + if (i < count - 1) { + createSB.append(","); + } + createSB.append("\n"); + } + } + } + + StringBuffer sql = new StringBuffer(); + + boolean includeDrop = JSONUtilities.getBoolean(options, "includeDropStatement", false); + if (includeDrop) { + sql.append("DROP TABLE " + table + ";\n"); + } + + sql.append("CREATE TABLE ").append(table); + sql.append(" (").append("\n"); + sql.append(createSB.toString()); + sql.append(")").append(";" + "\n"); + + String createSQL = sql.toString(); + if(logger.isDebugEnabled()){ + logger.debug("Create SQL Generated Successfully...{}", createSQL); + } + return createSQL; + } + +} diff --git a/main/src/com/google/refine/exporters/sql/SqlData.java b/main/src/com/google/refine/exporters/sql/SqlData.java new file mode 100755 index 000000000..6e595b733 --- /dev/null +++ b/main/src/com/google/refine/exporters/sql/SqlData.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018, Tony Opara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of Google nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.google.refine.exporters.sql; + + +public class SqlData { + + final public String columnName; + final public Object value; + final public String text; + + public SqlData(String columnName, Object value, String text) { + this.columnName = columnName; + this.value = value; + this.text = text; + + } + + + public String getColumnName() { + return columnName; + } + + + public Object getValue() { + return value; + } + + + public String getText() { + return text; + } + +} diff --git a/main/src/com/google/refine/exporters/sql/SqlExporter.java b/main/src/com/google/refine/exporters/sql/SqlExporter.java new file mode 100755 index 000000000..67fa176aa --- /dev/null +++ b/main/src/com/google/refine/exporters/sql/SqlExporter.java @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2018, Tony Opara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of Google nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.google.refine.exporters.sql; + +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.refine.ProjectManager; +import com.google.refine.browsing.Engine; +import com.google.refine.exporters.CustomizableTabularExporterUtilities; +import com.google.refine.exporters.TabularSerializer; +import com.google.refine.exporters.WriterExporter; +import com.google.refine.model.Project; +import com.google.refine.util.JSONUtilities; + +public class SqlExporter implements WriterExporter { + + public static final String NO_COL_SELECTED_ERROR = "****NO COLUMNS SELECTED****"; + public static final String NO_OPTIONS_PRESENT_ERROR = "****NO OPTIONS PRESENT****"; + + private final static Logger logger = LoggerFactory.getLogger("SqlExporter"); + + private List columnNames = new ArrayList(); + private List> sqlDataList = new ArrayList>(); + private JSONObject sqlOptions; + + @Override + public String getContentType() { + return "text/plain"; + } + + @Override + public void export(final Project project, Properties params, Engine engine, final Writer writer) + throws IOException { + + TabularSerializer serializer = new TabularSerializer() { + + @Override + public void startFile(JSONObject options) { + sqlOptions = options; + //logger.info("setting options::{}", sqlOptions); + } + + @Override + public void endFile() { + try { + if (columnNames.isEmpty()) { + writer.write(NO_COL_SELECTED_ERROR); + logger.error("No Columns Selected!!"); + return; + } + if (sqlOptions == null) { + writer.write(NO_OPTIONS_PRESENT_ERROR); + logger.error("No Options Selected!!"); + return; + } + String tableName = ProjectManager.singleton.getProjectMetadata(project.id).getName(); + + Object tableNameManual = sqlOptions.get("tableName"); + + if (tableNameManual != null && !tableNameManual.toString().isEmpty()) { + tableName = tableNameManual.toString(); + } + + SqlCreateBuilder createBuilder = new SqlCreateBuilder(tableName, columnNames, sqlOptions); + SqlInsertBuilder insertBuilder = new SqlInsertBuilder(tableName, columnNames, sqlDataList, + sqlOptions); + + final boolean includeStructure = sqlOptions == null ? true + : JSONUtilities.getBoolean(sqlOptions, "includeStructure", true); + + final boolean includeContent = sqlOptions == null ? true + : JSONUtilities.getBoolean(sqlOptions, "includeContent", true); + + if (includeStructure) { + String sqlCreateStr = createBuilder.getCreateSQL(); + writer.write(sqlCreateStr); + + } + + if (includeContent) { + String sqlInsertStr = insertBuilder.getInsertSQL(); + writer.write(sqlInsertStr); + } + + if (logger.isDebugEnabled()) { + logger.debug("sqlOptions::{}", sqlOptions); + } + + columnNames = new ArrayList(); + sqlDataList = new ArrayList>(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void addRow(List cells, boolean isHeader) { + + if (isHeader) { + for (CellData cellData : cells) { + columnNames.add(cellData.text); + } + + } else { + ArrayList values = new ArrayList<>(); + for (CellData cellData : cells) { + + if (cellData != null && cellData.text != null) { + SqlData newSql = new SqlData(cellData.columnName, cellData.value, cellData.text); + values.add(newSql); + + } + + } + sqlDataList.add(values); + } + + } + }; + + CustomizableTabularExporterUtilities.exportRows(project, engine, params, serializer); + } +} diff --git a/main/src/com/google/refine/exporters/sql/SqlInsertBuilder.java b/main/src/com/google/refine/exporters/sql/SqlInsertBuilder.java new file mode 100755 index 000000000..7e9e77a1b --- /dev/null +++ b/main/src/com/google/refine/exporters/sql/SqlInsertBuilder.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2018, Tony Opara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of Google nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.google.refine.exporters.sql; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.refine.util.JSONUtilities; + +public class SqlInsertBuilder { + + private static final Logger logger = LoggerFactory.getLogger("SQLInsertBuilder"); + + private String table; + + private List columns; + + private List> sqlDataList; + + private JSONObject options; + + /** + * + * @param table + * @param columns + * @param rows + * @param options + */ + public SqlInsertBuilder(String table, List columns, List> rows, JSONObject options) { + this.table = table; + this.columns = columns; + this.sqlDataList = rows; + this.options = options; + } + + /** + * Get Insert Sql + * @return + */ + public String getInsertSQL() { + // logger.info("options values::::{}", options); + JSONArray columnOptionArray = options == null ? null : + JSONUtilities.getArray(options, "columns"); + //logger.info("columnOptionArray::::{}", columnOptionArray); + + Map colOptionsMap = new HashMap(); + if(columnOptionArray != null) { + columnOptionArray.forEach(c -> { + JSONObject json = (JSONObject)c; + colOptionsMap.put("" + json.get("name"), json); + }); + } + + String colNamesWithSep = columns.stream() + .collect(Collectors.joining(",")); + StringBuffer values = new StringBuffer(); + + int idx = 0; + for(ArrayList sqlCellData : sqlDataList) { + StringBuilder rowValue = new StringBuilder(); + //logger.info(" row.size:{}", row.size()); + for(SqlData val : sqlCellData) { + + JSONObject jsonOb = colOptionsMap.get(val.getColumnName()); + String type = (String)jsonOb.get("type"); + if(type == null) { + type = "VARCHAR"; + } + if(type.equals("VARCHAR") || type.equals("CHAR") || type.equals("TEXT")) { + + String value = "'" + val.text + "'"; + rowValue.append(value); + }else { + rowValue.append(val.text); + } + + rowValue.append(","); + //logger.info("jsonObject:{}", jsonOb); + + } + idx++; + String rowValString = rowValue.toString(); + rowValString = rowValString.substring(0, rowValString.length() - 1); + + values.append("( "); + values.append(rowValString); + values.append(" )"); + if(idx < sqlDataList.size()) { + values.append(","); + } + values.append("\n"); +// logger.info("running values:{}", values.toString()); + + } + + + String valuesString = values.toString(); + valuesString = valuesString.substring(0, valuesString.length() - 1); + + + StringBuffer sql = new StringBuffer(); + + sql.append("INSERT INTO ").append(table); + sql.append(" ("); + sql.append(colNamesWithSep); + sql.append(") VALUES ").append("\n"); + sql.append(valuesString); + + String sqlString = sql.toString(); + if(logger.isDebugEnabled()) { + logger.debug("Insert Statement Generated Successfully...{}", sqlString); + } + return sqlString; + } + +} diff --git a/main/tests/server/src/com/google/refine/tests/exporters/sql/SqlExporterTests.java b/main/tests/server/src/com/google/refine/tests/exporters/sql/SqlExporterTests.java new file mode 100644 index 000000000..e78ebf069 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/exporters/sql/SqlExporterTests.java @@ -0,0 +1,304 @@ +/* + +Copyright 2018, Tony Opara. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +package com.google.refine.tests.exporters.sql; + +import static org.junit.Assert.assertNotEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.List; +import java.util.Properties; +import java.util.stream.Collectors; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import com.google.refine.ProjectManager; +import com.google.refine.browsing.Engine; +import com.google.refine.exporters.sql.SqlCreateBuilder; +import com.google.refine.exporters.sql.SqlExporter; +import com.google.refine.exporters.sql.SqlInsertBuilder; +import com.google.refine.model.Cell; +import com.google.refine.model.Column; +import com.google.refine.model.ModelException; +import com.google.refine.model.Project; +import com.google.refine.model.Row; +import com.google.refine.model.medadata.ProjectMetadata; +import com.google.refine.tests.ProjectManagerStub; +import com.google.refine.tests.RefineTest; + + +public class SqlExporterTests extends RefineTest { + + private static final String TEST_PROJECT_NAME = "SQL_EXPORTER_TEST_PROJECT"; + + @Override + @BeforeTest + public void init() { + logger = LoggerFactory.getLogger(this.getClass()); + } + + //dependencies + StringWriter writer; + ProjectMetadata projectMetadata; + Project project; + Engine engine; + Properties options; + SqlCreateBuilder sqlCreateBuilder; + SqlInsertBuilder sqlInsertBuilder; + + //System Under Test + SqlExporter SUT; + + @BeforeMethod + public void SetUp(){ + SUT = new SqlExporter(); + writer = new StringWriter(); + ProjectManager.singleton = new ProjectManagerStub(); + projectMetadata = new ProjectMetadata(); + project = new Project(); + projectMetadata.setName(TEST_PROJECT_NAME); + ProjectManager.singleton.registerProject(project, projectMetadata); + engine = new Engine(project); + options = mock(Properties.class); + } + + @AfterMethod + public void TearDown(){ + SUT = null; + writer = null; + ProjectManager.singleton.deleteProject(project.id); + project = null; + projectMetadata = null; + engine = null; + options = null; + sqlCreateBuilder = null; + sqlInsertBuilder = null; + } + + @Test + public void testExportSimpleSql(){ + createGrid(2, 2); + String tableName = "sql_table_test"; + String optionsString = createOptionsFromProject(tableName, null,null).toString(); + when(options.getProperty("options")).thenReturn(optionsString); + + try { + SUT.export(project, options, engine, writer); + } catch (IOException e) { + Assert.fail(); + } + + String result = writer.toString(); + // logger.info("result = \n" + result); + Assert.assertNotNull(result); + assertNotEquals(writer.toString(), SqlExporter.NO_OPTIONS_PRESENT_ERROR); + boolean checkResult = result.contains("CREATE TABLE " + tableName); + //logger.info("checkResult1 =" + checkResult); + checkResult = result.contains("INSERT INTO " + tableName); + // logger.info("checkResult2 =" + checkResult); + Assert.assertEquals(checkResult, true); + + } + + @Test + public void testExportSqlNoSchema(){ + createGrid(2, 2); + String tableName = "sql_table_test"; + JSONObject optionsJson = createOptionsFromProject(tableName, null,null); + optionsJson.put("includeStructure", false); + when(options.getProperty("options")).thenReturn(optionsJson.toString()); + // logger.info("Options = " + optionsJson.toString()); + + try { + SUT.export(project, options, engine, writer); + } catch (IOException e) { + Assert.fail(); + } + + String result = writer.toString(); + //logger.info("result = \n" + result); + Assert.assertNotNull(result); + assertNotEquals(writer.toString(), SqlExporter.NO_OPTIONS_PRESENT_ERROR); + boolean checkResult = result.contains("CREATE TABLE " + tableName); + Assert.assertEquals(checkResult, false); + + checkResult = result.contains("INSERT INTO " + tableName); + Assert.assertEquals(checkResult, true); + + } + + @Test + public void testExportSqlNoContent(){ + createGrid(2, 2); + String tableName = "sql_table_test"; + JSONObject optionsJson = createOptionsFromProject(tableName, null, null); + optionsJson.put("includeContent", false); + when(options.getProperty("options")).thenReturn(optionsJson.toString()); + //logger.info("Options = " + optionsJson.toString()); + + try { + SUT.export(project, options, engine, writer); + } catch (IOException e) { + Assert.fail(); + } + + String result = writer.toString(); + // logger.info("result = \n" + result); + Assert.assertNotNull(result); + assertNotEquals(writer.toString(), SqlExporter.NO_OPTIONS_PRESENT_ERROR); + boolean checkResult = result.contains("CREATE TABLE " + tableName); + Assert.assertEquals(checkResult, true); + + checkResult = result.contains("INSERT INTO " + tableName); + Assert.assertEquals(checkResult, false); + + } + + @Test + public void testExportSqlIncludeSchemaWithDropStmt(){ + createGrid(2, 2); + String tableName = "sql_table_test"; + JSONObject optionsJson = createOptionsFromProject(tableName, null, null); + optionsJson.put("includeStructure", true); + optionsJson.put("includeDropStatement", true); + + when(options.getProperty("options")).thenReturn(optionsJson.toString()); + //logger.info("Options = " + optionsJson.toString()); + + try { + SUT.export(project, options, engine, writer); + } catch (IOException e) { + Assert.fail(); + } + + String result = writer.toString(); + + Assert.assertNotNull(result); + assertNotEquals(writer.toString(), SqlExporter.NO_OPTIONS_PRESENT_ERROR); + assertNotEquals(writer.toString(), SqlExporter.NO_COL_SELECTED_ERROR); + + boolean checkResult = result.contains("CREATE TABLE " + tableName); + Assert.assertEquals(checkResult, true); + + checkResult = result.contains("INSERT INTO " + tableName ); + Assert.assertEquals(checkResult, true); + + checkResult = result.contains("DROP TABLE " + tableName + ";"); + Assert.assertEquals(checkResult, true); + + } + + @Test + public void testGetCreateSql(){ + createGrid(3,3); + String tableName = "sql_table_test"; + String type = "CHAR"; + String size = "2"; + JSONObject optionsJson = createOptionsFromProject(tableName, type, size); + // logger.info("Options:: = " + optionsJson.toString()); + List columns = project.columnModel.columns.stream().map(col -> col.getName()).collect(Collectors.toList()); + + sqlCreateBuilder = new SqlCreateBuilder(tableName, columns, optionsJson); + String createSql = sqlCreateBuilder.getCreateSQL(); + //logger.info("createSql = \n" + createSql); + Assert.assertNotNull(createSql); + boolean result = createSql.contains(type + "(" + size + ")"); + Assert.assertEquals(result, true); + + } + + //helper methods + protected void createColumns(int noOfColumns){ + for(int i = 0; i < noOfColumns; i++){ + try { + project.columnModel.addColumn(i, new Column(i, "column" + i), true); + } catch (ModelException e1) { + Assert.fail("Could not create column"); + } + } + } + + protected void createGrid(int noOfRows, int noOfColumns){ + createColumns(noOfColumns); + + for(int i = 0; i < noOfRows; i++){ + Row row = new Row(noOfColumns); + for(int j = 0; j < noOfColumns; j++){ + row.cells.add(new Cell("row" + i + "cell" + j, null)); + } + project.rows.add(row); + } + } + + protected JSONObject createOptionsFromProject(String tableName, String type, String size) { + + JSONObject json = new JSONObject(); + JSONArray columns = new JSONArray(); + json.put("columns", columns); + json.put("tableName", tableName); + + List cols = project.columnModel.columns; + + cols.forEach(c -> { + //logger.info("Column Name = " + c.getName()); + JSONObject columnModel = new JSONObject(); + columnModel.put("name", c.getName()); + columnModel.put("type", "VARCHAR"); + columnModel.put("size", "100"); + if(type != null) { + columnModel.put("type", type); + } + if(size != null) { + // logger.info(" Size = " + size); + columnModel.put("size", size); + } + + columns.put(columnModel); + + }); + + return json; + } + + +} diff --git a/main/webapp/modules/core/MOD-INF/controller.js b/main/webapp/modules/core/MOD-INF/controller.js index 23e5304eb..a11a5f238 100644 --- a/main/webapp/modules/core/MOD-INF/controller.js +++ b/main/webapp/modules/core/MOD-INF/controller.js @@ -467,6 +467,7 @@ function init() { "scripts/dialogs/templating-exporter-dialog.js", "scripts/dialogs/column-reordering-dialog.js", "scripts/dialogs/custom-tabular-exporter-dialog.js", + "scripts/dialogs/sql-exporter-dialog.js", "scripts/dialogs/expression-column-dialog.js", "scripts/project/edit-general-metadata-dialog.js", "scripts/dialogs/http-headers-dialog.js", @@ -506,7 +507,7 @@ function init() { "styles/dialogs/scatterplot-dialog.less", "styles/dialogs/column-reordering-dialog.less", "styles/dialogs/custom-tabular-exporter-dialog.less", - + "styles/dialogs/sql-exporter-dialog.less", "styles/reconciliation/recon-dialog.less", "styles/reconciliation/standard-service-panel.less", "styles/reconciliation/extend-data-preview-dialog.less", diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index aff50f5bb..be9ca529a 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -237,7 +237,7 @@ "help": "Help", "opt-code-applied": "Option code successfully applied.", "error-apply-code": "Error applying option code", - "custom-tab-exp": "Custom Tabular Exporter", + "custom-tab-exp": "SQL Exporter", "content": "Content", "download": "Download", "upload": "Upload", @@ -273,7 +273,13 @@ "char-enc": "Character encoding", "line-sep": "Line separator", "upload-to": "Upload to", - "json-text": "The following JSON text encodes the options you have set in the other tabs. You can copy it out and save it for later, and paste it back in and click Apply to re-use the same options." + "json-text": "The following JSON text encodes the options you have set in the other tabs. You can copy it out and save it for later, and paste it back in and click Apply to re-use the same options.", + "columnType": "SQL Type", + "for-include-structure-checkbox": "Include Schema", + "for-include-drop-statement-checkbox": "Include Drop Statement", + "for-include-content-checkbox": "Include Content", + "tableNameLabel": "Table Name:" + }, "core-facets": { "remove-facet": "Remove this facet", @@ -344,6 +350,7 @@ "triple-loader": "Triple loader", "mqlwrite": "MQLWrite", "custom-tabular": "Custom tabular exporter...", + "sql-export": "SQL Exporter...", "templating": "Templating...", "warning-align": "You haven't done any schema alignment yet,\n so there is no triple to export.\n\n Use the Freebase > Edit Schema Alignment Skeleton...\n command to align your data with Freebase schemas first.", "json-invalid": "The JSON you pasted is invalid", diff --git a/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.html b/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.html new file mode 100755 index 000000000..136ef7a53 --- /dev/null +++ b/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.html @@ -0,0 +1,110 @@ +
+
+
+
+
    +
  • +
  • +
+ +
+
+ + + + + + + + + + + +
+ + +
+
+ + + + + + + + + + +
Field NameSQL TypeSize
+
+ +
+
+ + +
+ + + + + + +
+ + + + + + +
+
+ +
\ No newline at end of file diff --git a/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.js b/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.js new file mode 100755 index 000000000..411003f9f --- /dev/null +++ b/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.js @@ -0,0 +1,408 @@ +/* + * Copyright (c) 2017, Tony Opara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of Google nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +function SqlExporterDialog(options) { + options = options || { + format: 'sql', + encoding: 'UTF-8', + outputBlankRows: false, + columns: null + }; + + this._columnOptionMap = {}; + this._createDialog(options); + } + + + SqlExporterDialog.uploadTargets = []; + + SqlExporterDialog.prototype._createDialog = function(options) { + var self = this; + + this._dialog = $(DOM.loadHTML("core", "scripts/dialogs/sql-exporter-dialog.html")); + this._elmts = DOM.bind(this._dialog); + this._level = DialogSystem.showDialog(this._dialog); + + + this._elmts.dialogHeader.html($.i18n._('core-dialogs')["custom-tab-exp"]); + this._elmts.or_dialog_content.html($.i18n._('core-dialogs')["content"]); + this._elmts.or_dialog_download.html($.i18n._('core-dialogs')["download"]); + + this._elmts.selectAllButton.html($.i18n._('core-buttons')["select-all"]); + this._elmts.deselectAllButton.html($.i18n._('core-buttons')["deselect-all"]); + + this._elmts.or_dialog_outEmptyRow.html($.i18n._('core-dialogs')["out-empty-row"]); + + this._elmts.downloadPreviewButton.html($.i18n._('core-buttons')["preview"]); + this._elmts.downloadButton.html($.i18n._('core-buttons')["download"]); + + this._elmts.cancelButton.html($.i18n._('core-buttons')["cancel"]); +// this._elmts.nextButton.html($.i18n._('core-buttons')["next"]); + + + this._elmts.tableNameLabel.html($.i18n._('core-dialogs')["tableNameLabel"]); + this._elmts.includeStructureLabel.html($.i18n._('core-dialogs')["for-include-structure-checkbox"]); + this._elmts.includeDropStatementLabel.html($.i18n._('core-dialogs')["for-include-drop-statement-checkbox"]); + this._elmts.includeContentLabel.html($.i18n._('core-dialogs')["for-include-content-checkbox"]); + + + $("#sql-exporter-tabs-content").css("display", ""); + $("#sql-exporter-tabs-download").css("display", ""); + $("#sql-exporter-tabs").tabs(); + + + /* + * Populate column list. + */ + for (var i = 0; i < theProject.columnModel.columns.length; i++) { + var column = theProject.columnModel.columns[i]; + var name = column.name; + var rowId = "sql-exporter-dialog-row" + i; + var selectBoxName = 'selectBoxRow' + i; + var sizeInputName = 'sizeInputRow' + i; + var applyAllBtnName = 'applyAllBtn' + i; + + var arr = [ + {val : 'VARCHAR', text: 'VARCHAR'}, + {val : 'TEXT', text: 'TEXT'}, + {val : 'INT', text: 'INT'}, + {val : 'NUMERIC', text: 'NUMERIC'}, + {val : 'CHAR', text: 'CHAR'}, + {val : 'DATE', text: 'DATE'}, + {val : 'TIMESTAMP', text: 'TIMESTAMP'} + ]; + + var sel = $('') + .attr('type', 'checkbox') + .attr('checked', 'checked') + .addClass("columnNameCheckboxStyle") + .appendTo(columnCell); + $('') + .text(name) + .appendTo(columnCell); + + var typeCell = $('') + .attr('width', '150px') + .appendTo(row); + sel.appendTo(typeCell); + + var sizeCell = $('') + .attr('width', '20px') + .appendTo(row); + $('') + .attr('type', 'text') + .attr('size', '8px') + .attr('id', sizeInputName) + .addClass("sql-exporter-dialog-input") + .appendTo(sizeCell); + + var applyAllCell = $('') + .attr('width', '60px') + .appendTo(row); + $('') + .attr('type', 'button') + .attr('value', 'Apply All') + .attr('id', applyAllBtnName) + .attr("rowIndex", i) + .appendTo(applyAllCell); + + $('#' + applyAllBtnName).on('click', function() { + var rowIndex = this.getAttribute('rowIndex'); + var typeValue = $("#selectBoxRow" + rowIndex).val(); + var sizeValue = $("#sizeInputRow" + rowIndex).val(); + + $('select.typeSelectClass').each(function() { + //alert("Value:" + this.value + " RowIndex:" + rowIndex + " TypeValue:" + typeValue + "" + this.value); + var rowId = this.getAttribute('rowIndex'); + var id = this.getAttribute('id'); + if(rowIndex !== rowId){ + $("#" + id).val(typeValue); + } + + }); + $('input.sql-exporter-dialog-input').each(function() { + //alert("Value:" + this.value + " RowIndex:" + rowIndex + " TypeValue:" + typeValue + "" + this.value); + var rowId = this.getAttribute('rowIndex'); + var id = this.getAttribute('id'); + if(rowIndex !== rowId){ + $("#" + id).val(sizeValue); + } + + + }); + + }); + + this._columnOptionMap[name] = { + name: name, + type: '', + size: '' + + }; + } + + + this._elmts.selectAllButton.click(function() { + $("input:checkbox[class=columnNameCheckboxStyle]").each(function () { + $(this).attr('checked', true) + }); + self._updateOptionCode(); + }); + this._elmts.deselectAllButton.click(function() { + $("input:checkbox[class=columnNameCheckboxStyle]").each(function () { + $(this).attr('checked', false) + }); + self._updateOptionCode(); + }); + + this._elmts.includeStructureCheckbox.click(function() { + var checked = $(this).is(':checked'); + //alert('checked ' + checked); + if(checked == true){ + $('#includeDropStatementCheckboxId').removeAttr("disabled"); + }else{ + $('#includeDropStatementCheckboxId').attr("disabled", true); + } + }); + + + this._elmts.cancelButton.click(function() { self._dismiss(); }); + this._elmts.downloadButton.click(function() { self._download(); }); + this._elmts.downloadPreviewButton.click(function(evt) { self._previewDownload(); }); + + this._configureUIFromOptionCode(options); + this._updateOptionCode(); + }; + + SqlExporterDialog.prototype._configureUIFromOptionCode = function(options) { + + this._elmts.tableNameTextBox.val(theProject.metadata.name); + this._elmts.outputEmptyRowsCheckbox.attr('checked', 'checked'); + + }; + + SqlExporterDialog.prototype._dismiss = function() { + DialogSystem.dismissUntil(this._level - 1); + }; + + SqlExporterDialog.prototype._previewDownload = function() { + this._postExport(true); + }; + + SqlExporterDialog.prototype._download = function() { + var result = this._postExport(false); + // alert("result::" + result); + if(result == true){ + this._dismiss(); + } + + }; + + SqlExporterDialog.prototype._postExport = function(preview) { + // var exportAllRowsCheckbox = this._elmts.exportAllRowsCheckbox[0].checked; + var options = this._getOptionCode(); + + if(options.columns == null || options.columns.length == 0){ + alert("Please select at least one column..."); + return false; + } + + var format = options.format; + var encoding = options.encoding; + + delete options.format; + delete options.encoding; + if (preview) { + options.limit = 10; + } + + // var ext = SqlExporterDialog.formats[format].extension; + var form = this._prepareSqlExportRowsForm(format, false, "sql"); + $('') + .attr("name", "options") + .attr("value", JSON.stringify(options)) + .appendTo(form); + if (encoding) { + $('') + .attr("name", "encoding") + .attr("value", encoding) + .appendTo(form); + } + if (!preview) { + $('') + .attr("name", "contentType") + .attr("value", "application/x-unknown") // force download + .appendTo(form); + } + + // alert("form::" + form); + document.body.appendChild(form); + + window.open("about:blank", "refine-export"); + form.submit(); + + document.body.removeChild(form); + return true; + }; + + SqlExporterDialog.prototype._prepareSqlExportRowsForm = function(format, includeEngine, ext) { + var name = $.trim(theProject.metadata.name.replace(/\W/g, ' ')).replace(/\s+/g, '-'); + var form = document.createElement("form"); + $(form) + .css("display", "none") + .attr("method", "post") + .attr("action", "command/core/export-rows/" + name + ((ext) ? ("." + ext) : "")) + .attr("target", "refine-export"); + + $('') + .attr("name", "project") + .attr("value", theProject.id) + .appendTo(form); + $('') + .attr("name", "format") + .attr("value", format) + .appendTo(form); + if (includeEngine) { + $('') + .attr("name", "engine") + .attr("value", JSON.stringify(ui.browsingEngine.getJSON())) + .appendTo(form); + } + + return form; + }; + + SqlExporterDialog.prototype._selectColumn = function(columnName) { + + this._elmts.columnNameSpan.text(columnName); + var columnOptions = this._columnOptionMap[columnName]; + alert("in _selectColumn:column type::" + columnOptions.type); + + }; + + SqlExporterDialog.prototype._updateCurrentColumnOptions = function() { +// var selectedColumnName = this._elmts.columnList.find('.sql-exporter-dialog-column.selected').attr('column'); +// //alert("_updateCurrentColumnOptions::" + selectedColumnName); +// var columnOptions = this._columnOptionMap[selectedColumnName]; +// columnOptions.type= this._elmts.columnOptionPane.find('input[name="sql-exporter-type"]:checked').val(); + + }; + + SqlExporterDialog.prototype._updateOptionCode = function() { + this._elmts.optionCodeInput.val(JSON.stringify(this._getOptionCode(), null, 2)); + }; + + + SqlExporterDialog.prototype._getOptionCode = function() { + var options = { + //format: this._dialog.find('input[name="sql-exporter-download-format"]:checked').val() + }; + var unescapeJavascriptString = function(s) { + try { + return JSON.parse('"' + s + '"'); + } catch (e) { + // We're not handling the case where the user doesn't escape double quotation marks. + return s; + } + }; + + options.format = 'sql'; + options.separator = ';'; + options.encoding = 'UTF-8'; + + options.outputBlankRows = this._elmts.outputEmptyRowsCheckbox[0].checked; + options.includeStructure = this._elmts.includeStructureCheckbox[0].checked; + options.includeDropStatement = this._elmts.includeDropStatementCheckbox[0].checked; + options.includeContent = this._elmts.includeContentCheckbox[0].checked; + options.tableName = $.trim(this._elmts.tableNameTextBox.val().replace(/\W/g, ' ')).replace(/\s+/g, '-'); + + + options.columns = []; + + var self = this; + this._elmts.columnListTable.find('.sql-exporter-dialog-row').each(function() { + if ($(this).find('input[type="checkbox"]')[0].checked) { + var name = this.getAttribute('column'); + var rowIndex = this.getAttribute('rowIndex'); + // alert("column::"+ name + " rowIndex::" + rowIndex); + + var selectedValue = $('#selectBoxRow' + rowIndex).val(); + //alert("selectedValue::"+ selectedValue); + var typeSize = 0; + if(selectedValue == 'VARCHAR' || selectedValue == 'CHAR' || selectedValue == 'INT' || selectedValue == 'NUMERIC'){ + typeSize = $('#sizeInputRow' + rowIndex).val(); + // alert("typeSize::" + typeSize); + } + + var fullColumnOptions = self._columnOptionMap[name]; + var columnOptions = { + name: name, + type: selectedValue, + size: typeSize + + }; + + // alert('checked type ' + columnIndex + ' =' + check_value); + + options.columns.push(columnOptions); + } + }); + //alert('options:' + options); + return options; + }; + \ No newline at end of file diff --git a/main/webapp/modules/core/scripts/project/exporters.js b/main/webapp/modules/core/scripts/project/exporters.js index 13eba106c..f6e5af26e 100644 --- a/main/webapp/modules/core/scripts/project/exporters.js +++ b/main/webapp/modules/core/scripts/project/exporters.js @@ -97,6 +97,11 @@ ExporterManager.MenuItems = [ "label": $.i18n._('core-project')["custom-tabular"], "click": function() { new CustomTabularExporterDialog(); } }, + { + "id" : "core/export-sql", + "label": $.i18n._('core-project')["sql-export"], + "click": function() { new SqlExporterDialog(); } + }, { "id" : "core/export-templating", "label": $.i18n._('core-project')["templating"], @@ -142,6 +147,7 @@ ExporterManager.handlers.exportRows = function(format, ext) { ExporterManager.prepareExportRowsForm = function(format, includeEngine, ext) { var name = $.trim(theProject.metadata.name.replace(/\W/g, ' ')).replace(/\s+/g, '-'); + //alert("name:" + name); var form = document.createElement("form"); $(form) .css("display", "none") diff --git a/main/webapp/modules/core/styles/dialogs/sql-exporter-dialog.less b/main/webapp/modules/core/styles/dialogs/sql-exporter-dialog.less new file mode 100644 index 000000000..4915575be --- /dev/null +++ b/main/webapp/modules/core/styles/dialogs/sql-exporter-dialog.less @@ -0,0 +1,94 @@ +/* + +Copyright 2010, Google Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +@import-less url("../theme.less"); + +#sql-exporter-tabs .ui-tabs-panel { + padding: @padding_looser; + } + +.sql-exporter-tabs-content-main { + +} +.sql-exporter-columns, .sql-exporter-column-options { + /*border: 1px solid @chrome_primary;*/ + height: 8em; + padding: @padding_loose; + } +.sql-exporter-columns { + min-height: 200px; + overflow: auto; + } +.sql-exporter-selected-column { + font-weight: bold; + border: 1px solid @chrome_primary; + background: @chrome_primary; + padding: @padding_tighter; + .rounded_corners(); + } + +.sql-exporter-dialog-column { + /* border: 1px solid @chrome_primary;*/ + background: @fill_secondary; + padding: @padding_tighter; + margin: @padding_tight; + cursor: move; + .rounded_corners(); + } +.sql-exporter-dialog-column.selected { + background: @chrome_primary; + font-weight: bold; + } + +textarea.sql-exporter-code { + width: 100%; + border: 1px solid @chrome_primary; + height: 25em; + } +.sql-exporter-dialog-row { + margin-top: 2px; + padding-top: 2px; + margin-bottom: 2px; + margin-top: 2px; +} +tr.sql-exporter-dialog-row td { + border:1px dashed lightblue; + margin: 2px; +} +.sql-exporter-dialog-input { + margin:2px; + border: solid 2px lightblue; +} +.typeSelectClass { + margin-left:2px; +} \ No newline at end of file