From 0c9396275abea473e521ca87dfbf4382d7c7ca4e Mon Sep 17 00:00:00 2001 From: Jacky Date: Sat, 21 Oct 2017 23:33:19 -0400 Subject: [PATCH 01/18] add the import options to metadata --- .classpath | 9 +++++---- .gitignore | 28 ---------------------------- 2 files changed, 5 insertions(+), 32 deletions(-) delete mode 100644 .gitignore diff --git a/.classpath b/.classpath index a47daf4bc..8448958a5 100644 --- a/.classpath +++ b/.classpath @@ -17,7 +17,6 @@ - @@ -77,7 +76,6 @@ - @@ -85,6 +83,9 @@ - - + + + + + diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d2340d41e..000000000 --- a/.gitignore +++ /dev/null @@ -1,28 +0,0 @@ -*~ -\#*# -.*.swp -*.DS_Store -*.class -.com.apple.timemachine.supported -.import-temp/ -build/ -dist/ -server/classes/ -main/webapp/WEB-INF/classes/ -main/tests/server/classes/ -main/test-output/ -appengine/classes/ -tools/ -extensions/sample-extension/module/MOD-INF/classes/ -extensions/jython/module/MOD-INF/classes/ -extensions/jython/module/MOD-INF/lib/cachedir/ -extensions/rdf-exporter/module/MOD-INF/classes/ -broker/appengine/module/MOD-INF/classes/ -broker/core/module/MOD-INF/classes/ -broker/core/WEB-INF/lib/ -broker/core/data/ -broker/core/test-output/ -tmp/ -/test-output -/bin -open-refine.log From 818e139b430ecb6afe89c3b1c68176d0b4875eef Mon Sep 17 00:00:00 2001 From: Jacky Date: Sat, 21 Oct 2017 23:33:19 -0400 Subject: [PATCH 02/18] add the import options to metadata --- .classpath | 9 ++--- .gitignore | 28 --------------- .../google/refine/pcaxis/PCAxisImporter.java | 2 ++ .../com/google/refine/ProjectMetadata.java | 36 +++++++++++++++++++ .../refine/importers/ExcelImporter.java | 2 ++ .../refine/importers/FixedWidthImporter.java | 2 ++ .../refine/importers/ImportingParserBase.java | 18 ++++++++-- .../google/refine/importers/JsonImporter.java | 2 ++ .../refine/importers/LineBasedImporter.java | 2 ++ .../google/refine/importers/OdsImporter.java | 2 ++ .../refine/importers/RdfTripleImporter.java | 2 ++ .../importers/SeparatorBasedImporter.java | 1 + .../importers/TabularImportingParserBase.java | 6 ++++ .../refine/importers/WikitextImporter.java | 2 ++ .../google/refine/importers/XmlImporter.java | 2 ++ .../tree/TreeImportingParserBase.java | 3 +- .../refine/io/ProjectMetadataUtilities.java | 5 +++ 17 files changed, 89 insertions(+), 35 deletions(-) delete mode 100644 .gitignore diff --git a/.classpath b/.classpath index a47daf4bc..8448958a5 100644 --- a/.classpath +++ b/.classpath @@ -17,7 +17,6 @@ - @@ -77,7 +76,6 @@ - @@ -85,6 +83,9 @@ - - + + + + + diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d2340d41e..000000000 --- a/.gitignore +++ /dev/null @@ -1,28 +0,0 @@ -*~ -\#*# -.*.swp -*.DS_Store -*.class -.com.apple.timemachine.supported -.import-temp/ -build/ -dist/ -server/classes/ -main/webapp/WEB-INF/classes/ -main/tests/server/classes/ -main/test-output/ -appengine/classes/ -tools/ -extensions/sample-extension/module/MOD-INF/classes/ -extensions/jython/module/MOD-INF/classes/ -extensions/jython/module/MOD-INF/lib/cachedir/ -extensions/rdf-exporter/module/MOD-INF/classes/ -broker/appengine/module/MOD-INF/classes/ -broker/core/module/MOD-INF/classes/ -broker/core/WEB-INF/lib/ -broker/core/data/ -broker/core/test-output/ -tmp/ -/test-output -/bin -open-refine.log diff --git a/extensions/pc-axis/src/com/google/refine/pcaxis/PCAxisImporter.java b/extensions/pc-axis/src/com/google/refine/pcaxis/PCAxisImporter.java index 984569e1b..64e78a67d 100644 --- a/extensions/pc-axis/src/com/google/refine/pcaxis/PCAxisImporter.java +++ b/extensions/pc-axis/src/com/google/refine/pcaxis/PCAxisImporter.java @@ -88,5 +88,7 @@ public class PCAxisImporter extends TabularImportingParserBase { TabularImportingParserBase.readTable( project, metadata, job, dataReader, fileSource, limit, options, exceptions); + + super.parseOneFile(project, metadata, job, fileSource, reader, limit, options, exceptions); } } diff --git a/main/src/com/google/refine/ProjectMetadata.java b/main/src/com/google/refine/ProjectMetadata.java index cd0f3f476..5aa574d5b 100644 --- a/main/src/com/google/refine/ProjectMetadata.java +++ b/main/src/com/google/refine/ProjectMetadata.java @@ -40,6 +40,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Properties; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONWriter; @@ -61,6 +62,10 @@ public class ProjectMetadata implements Jsonizable { private String _encoding; private int _encodingConfidence; + private String _description; + // import options is an array for 1-n data sources + private JSONArray _importOptionMetaData = new JSONArray(); + private Map _customMetadata = new HashMap(); private PreferenceStore _preferenceStore = new PreferenceStore(); @@ -99,6 +104,12 @@ public class ProjectMetadata implements Jsonizable { } writer.endObject(); + // write JSONArray to file directly + if (_importOptionMetaData.length() > 0 ) { + writer.key("importOptionMetaData"); + writer.value(_importOptionMetaData); + } + if ("save".equals(options.getProperty("mode"))) { writer.key("password"); writer.value(_password); @@ -182,6 +193,16 @@ public class ProjectMetadata implements Jsonizable { // ignore } } + + if (obj.has("importOptionMetaData") && !obj.isNull("importOptionMetaData")) { + try { + JSONArray jsonArray = obj.getJSONArray("importOptionMetaData"); + pm._importOptionMetaData = jsonArray; + } catch (JSONException e) { + // ignore + } + } + pm.written = new Date(); // Mark it as not needing writing until modified @@ -263,4 +284,19 @@ public class ProjectMetadata implements Jsonizable { } updateModified(); } + + public JSONArray getImportOptionMetaData() { + return _importOptionMetaData; + } + + public void setImportOptionMetaData(JSONArray jsonArray) { + _importOptionMetaData = jsonArray; + updateModified(); + } + + public void appendImportOptionMetaData(JSONObject obj) { + _importOptionMetaData.put(obj); + updateModified(); + } + } diff --git a/main/src/com/google/refine/importers/ExcelImporter.java b/main/src/com/google/refine/importers/ExcelImporter.java index 4de1b3369..5838d7a87 100644 --- a/main/src/com/google/refine/importers/ExcelImporter.java +++ b/main/src/com/google/refine/importers/ExcelImporter.java @@ -225,6 +225,8 @@ public class ExcelImporter extends TabularImportingParserBase { exceptions ); } + + super.parseOneFile(project, metadata, job, fileSource, inputStream, limit, options, exceptions); } static protected Serializable extractCell(org.apache.poi.ss.usermodel.Cell cell) { diff --git a/main/src/com/google/refine/importers/FixedWidthImporter.java b/main/src/com/google/refine/importers/FixedWidthImporter.java index fa3cd6ce2..89ca6ad0a 100644 --- a/main/src/com/google/refine/importers/FixedWidthImporter.java +++ b/main/src/com/google/refine/importers/FixedWidthImporter.java @@ -107,6 +107,8 @@ public class FixedWidthImporter extends TabularImportingParserBase { }; TabularImportingParserBase.readTable(project, metadata, job, dataReader, fileSource, limit, options, exceptions); + + super.parseOneFile(project, metadata, job, fileSource, reader, limit, options, exceptions); } /** diff --git a/main/src/com/google/refine/importers/ImportingParserBase.java b/main/src/com/google/refine/importers/ImportingParserBase.java index b36c452d2..b28bab03c 100644 --- a/main/src/com/google/refine/importers/ImportingParserBase.java +++ b/main/src/com/google/refine/importers/ImportingParserBase.java @@ -40,6 +40,7 @@ import java.io.Reader; import java.util.List; import org.apache.commons.lang.NotImplementedException; +import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,6 +50,7 @@ import com.google.refine.importers.ImporterUtilities.MultiFileReadingProgress; import com.google.refine.importing.ImportingJob; import com.google.refine.importing.ImportingParser; import com.google.refine.importing.ImportingUtilities; +import com.google.refine.io.ProjectMetadataUtilities; import com.google.refine.model.Column; import com.google.refine.model.ModelException; import com.google.refine.model.Project; @@ -145,7 +147,18 @@ abstract public class ImportingParserBase implements ImportingParser { JSONObject options, List exceptions ) { - throw new NotImplementedException(); +// throw new NotImplementedException(); + pushImportingOptions(metadata, fileSource, options); + } + + private void pushImportingOptions(ProjectMetadata metadata, String fileSource, JSONObject options) { + try { + options.put("fileSource", fileSource); + } catch (JSONException e) { + // ignore + } + // set the import options to metadata: + metadata.appendImportOptionMetaData(options); } public void parseOneFile( @@ -158,7 +171,8 @@ abstract public class ImportingParserBase implements ImportingParser { JSONObject options, List exceptions ) { - throw new NotImplementedException(); +// throw new NotImplementedException(); + pushImportingOptions(metadata, fileSource, options); } diff --git a/main/src/com/google/refine/importers/JsonImporter.java b/main/src/com/google/refine/importers/JsonImporter.java index 35aae5152..35092e83d 100644 --- a/main/src/com/google/refine/importers/JsonImporter.java +++ b/main/src/com/google/refine/importers/JsonImporter.java @@ -199,6 +199,8 @@ public class JsonImporter extends TreeImportingParserBase { parseOneFile(project, metadata, job, fileSource, new JSONTreeReader(is), rootColumnGroup, limit, options, exceptions); + + super.parseOneFile(project, metadata, job, fileSource, is, rootColumnGroup, limit, options, exceptions); } static public class JSONTreeReader implements TreeReader { diff --git a/main/src/com/google/refine/importers/LineBasedImporter.java b/main/src/com/google/refine/importers/LineBasedImporter.java index b3d0ad320..c0e561a77 100644 --- a/main/src/com/google/refine/importers/LineBasedImporter.java +++ b/main/src/com/google/refine/importers/LineBasedImporter.java @@ -104,5 +104,7 @@ public class LineBasedImporter extends TabularImportingParserBase { }; TabularImportingParserBase.readTable(project, metadata, job, dataReader, fileSource, limit, options, exceptions); + + super.parseOneFile(project, metadata, job, fileSource, reader, limit, options, exceptions); } } diff --git a/main/src/com/google/refine/importers/OdsImporter.java b/main/src/com/google/refine/importers/OdsImporter.java index 1fc927ffe..47f69f864 100644 --- a/main/src/com/google/refine/importers/OdsImporter.java +++ b/main/src/com/google/refine/importers/OdsImporter.java @@ -183,6 +183,8 @@ public class OdsImporter extends TabularImportingParserBase { exceptions ); } + + super.parseOneFile(project, metadata, job, fileSource, inputStream, limit, options, exceptions); } static protected Serializable extractCell(OdfTableCell cell) { diff --git a/main/src/com/google/refine/importers/RdfTripleImporter.java b/main/src/com/google/refine/importers/RdfTripleImporter.java index 739476c47..bd73402bb 100644 --- a/main/src/com/google/refine/importers/RdfTripleImporter.java +++ b/main/src/com/google/refine/importers/RdfTripleImporter.java @@ -160,5 +160,7 @@ public class RdfTripleImporter extends ImportingParserBase { } finally { triples.iterator().close(); } + + super.parseOneFile(project, metadata, job, fileSource, input, limit, options, exceptions); } } diff --git a/main/src/com/google/refine/importers/SeparatorBasedImporter.java b/main/src/com/google/refine/importers/SeparatorBasedImporter.java index 4980b0a87..ec662486e 100644 --- a/main/src/com/google/refine/importers/SeparatorBasedImporter.java +++ b/main/src/com/google/refine/importers/SeparatorBasedImporter.java @@ -121,6 +121,7 @@ public class SeparatorBasedImporter extends TabularImportingParserBase { }; TabularImportingParserBase.readTable(project, metadata, job, dataReader, fileSource, limit, options, exceptions); + super.parseOneFile(project, metadata, job, fileSource, lnReader, limit, options, exceptions); } static protected ArrayList getCells(String line, CSVParser parser, LineNumberReader lnReader) diff --git a/main/src/com/google/refine/importers/TabularImportingParserBase.java b/main/src/com/google/refine/importers/TabularImportingParserBase.java index c00ab91cb..c7cdff217 100644 --- a/main/src/com/google/refine/importers/TabularImportingParserBase.java +++ b/main/src/com/google/refine/importers/TabularImportingParserBase.java @@ -34,6 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.importers; import java.io.IOException; +import java.io.Reader; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -200,4 +201,9 @@ abstract public class TabularImportingParserBase extends ImportingParserBase { exceptions.add(e); } } + + public void parseOneFile(Project project, ProjectMetadata metadata, ImportingJob job, String fileSource, + Reader dataReader, int limit, JSONObject options, List exceptions) { + super.parseOneFile(project, metadata, job, fileSource, dataReader, limit, options, exceptions); + } } diff --git a/main/src/com/google/refine/importers/WikitextImporter.java b/main/src/com/google/refine/importers/WikitextImporter.java index 1106256b3..2a5eb2706 100644 --- a/main/src/com/google/refine/importers/WikitextImporter.java +++ b/main/src/com/google/refine/importers/WikitextImporter.java @@ -731,6 +731,8 @@ public class WikitextImporter extends TabularImportingParserBase { exceptions.add(e1); e1.printStackTrace(); } + + super.parseOneFile(project, metadata, job, fileSource, reader, limit, options, exceptions); } private StandardReconConfig getReconConfig(String url) { diff --git a/main/src/com/google/refine/importers/XmlImporter.java b/main/src/com/google/refine/importers/XmlImporter.java index bc3cb9f86..92cb866d5 100644 --- a/main/src/com/google/refine/importers/XmlImporter.java +++ b/main/src/com/google/refine/importers/XmlImporter.java @@ -201,6 +201,8 @@ public class XmlImporter extends TreeImportingParserBase { try { parseOneFile(project, metadata, job, fileSource, new XmlParser(inputStream), rootColumnGroup, limit, options, exceptions); + + super.parseOneFile(project, metadata, job, fileSource, inputStream, rootColumnGroup, limit, options, exceptions); } catch (XMLStreamException e) { exceptions.add(e); } catch (IOException e) { diff --git a/main/src/com/google/refine/importers/tree/TreeImportingParserBase.java b/main/src/com/google/refine/importers/tree/TreeImportingParserBase.java index 1f2cfb403..9fceab5b1 100644 --- a/main/src/com/google/refine/importers/tree/TreeImportingParserBase.java +++ b/main/src/com/google/refine/importers/tree/TreeImportingParserBase.java @@ -174,7 +174,8 @@ abstract public class TreeImportingParserBase extends ImportingParserBase { JSONObject options, List exceptions ) { - throw new NotImplementedException(); + // throw new NotImplementedException(); + super.parseOneFile(project, metadata, job, fileSource, inputStream, limit, options, exceptions); } /** diff --git a/main/src/com/google/refine/io/ProjectMetadataUtilities.java b/main/src/com/google/refine/io/ProjectMetadataUtilities.java index bf220e3ae..75640597d 100644 --- a/main/src/com/google/refine/io/ProjectMetadataUtilities.java +++ b/main/src/com/google/refine/io/ProjectMetadataUtilities.java @@ -154,4 +154,9 @@ public class ProjectMetadataUtilities { reader.close(); } } + + public static void merge(ProjectMetadata metadata, JSONObject options) { + // TODO Auto-generated method stub + + } } From 63c1714d0a06dbebb142fcd09087ee945aa86225 Mon Sep 17 00:00:00 2001 From: Jacky Date: Sun, 22 Oct 2017 00:37:59 -0400 Subject: [PATCH 03/18] add fields for metadata --- .../com/google/refine/ProjectMetadata.java | 77 ++++++++++++++++++- .../refine/importers/ImportingParserBase.java | 4 - .../refine/io/ProjectMetadataUtilities.java | 5 -- 3 files changed, 74 insertions(+), 12 deletions(-) diff --git a/main/src/com/google/refine/ProjectMetadata.java b/main/src/com/google/refine/ProjectMetadata.java index 5aa574d5b..a63867622 100644 --- a/main/src/com/google/refine/ProjectMetadata.java +++ b/main/src/com/google/refine/ProjectMetadata.java @@ -62,7 +62,12 @@ public class ProjectMetadata implements Jsonizable { private String _encoding; private int _encodingConfidence; - private String _description; + private String _creator; + private String _contributors; + private String _subject; // Several refine projects may be linked + private String _description; // free form of comment + private int _rowNumber; // at the creation. Essential for cleaning old projects too heavy + // import options is an array for 1-n data sources private JSONArray _importOptionMetaData = new JSONArray(); @@ -95,7 +100,12 @@ public class ProjectMetadata implements Jsonizable { writer.key("name"); writer.value(_name); writer.key("created"); writer.value(ParsingUtilities.dateToString(_created)); writer.key("modified"); writer.value(ParsingUtilities.dateToString(_modified)); - + writer.key("creator"); writer.value(_creator); + writer.key("contributors"); writer.value(_contributors); + writer.key("subject"); writer.value(_subject); + writer.key("description"); writer.value(_description); + writer.key("rowNumber"); writer.value(_rowNumber); + writer.key("customMetadata"); writer.object(); for (String key : _customMetadata.keySet()) { Serializable value = _customMetadata.get(key); @@ -158,7 +168,13 @@ public class ProjectMetadata implements Jsonizable { pm._encoding = JSONUtilities.getString(obj, "encoding", ""); pm._encodingConfidence = JSONUtilities.getInt(obj, "encodingConfidence", 0); - + + pm._creator = JSONUtilities.getString(obj, "creator", ""); + pm._contributors = JSONUtilities.getString(obj, "contributors", ""); + pm._subject = JSONUtilities.getString(obj, "subject", ""); + pm._description = JSONUtilities.getString(obj, "description", ""); + pm._rowNumber = JSONUtilities.getInt(obj, "rowNumber", 0); + if (obj.has("preferences") && !obj.isNull("preferences")) { try { pm._preferenceStore.load(obj.getJSONObject("preferences")); @@ -298,5 +314,60 @@ public class ProjectMetadata implements Jsonizable { _importOptionMetaData.put(obj); updateModified(); } + + + public String get_creator() { + return _creator; + } + + + public void setCreator(String creator) { + this._creator = creator; + updateModified(); + } + + + public String get_contributors() { + return _contributors; + } + + + public void setContributors(String contributors) { + this._contributors = contributors; + updateModified(); + } + + + public String get_subject() { + return _subject; + } + + + public void setSubject(String subject) { + this._subject = subject; + updateModified(); + } + + + public String get_description() { + return _description; + } + + + public void setDescription(String description) { + this._description = description; + updateModified(); + } + + + public int getRowNumber() { + return _rowNumber; + } + + + public void setRowNumber(int rowNumber) { + this._rowNumber = rowNumber; + updateModified(); + } } diff --git a/main/src/com/google/refine/importers/ImportingParserBase.java b/main/src/com/google/refine/importers/ImportingParserBase.java index b28bab03c..5d9ed1c60 100644 --- a/main/src/com/google/refine/importers/ImportingParserBase.java +++ b/main/src/com/google/refine/importers/ImportingParserBase.java @@ -39,7 +39,6 @@ import java.io.InputStream; import java.io.Reader; import java.util.List; -import org.apache.commons.lang.NotImplementedException; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; @@ -50,7 +49,6 @@ import com.google.refine.importers.ImporterUtilities.MultiFileReadingProgress; import com.google.refine.importing.ImportingJob; import com.google.refine.importing.ImportingParser; import com.google.refine.importing.ImportingUtilities; -import com.google.refine.io.ProjectMetadataUtilities; import com.google.refine.model.Column; import com.google.refine.model.ModelException; import com.google.refine.model.Project; @@ -147,7 +145,6 @@ abstract public class ImportingParserBase implements ImportingParser { JSONObject options, List exceptions ) { -// throw new NotImplementedException(); pushImportingOptions(metadata, fileSource, options); } @@ -171,7 +168,6 @@ abstract public class ImportingParserBase implements ImportingParser { JSONObject options, List exceptions ) { -// throw new NotImplementedException(); pushImportingOptions(metadata, fileSource, options); } diff --git a/main/src/com/google/refine/io/ProjectMetadataUtilities.java b/main/src/com/google/refine/io/ProjectMetadataUtilities.java index 75640597d..bf220e3ae 100644 --- a/main/src/com/google/refine/io/ProjectMetadataUtilities.java +++ b/main/src/com/google/refine/io/ProjectMetadataUtilities.java @@ -154,9 +154,4 @@ public class ProjectMetadataUtilities { reader.close(); } } - - public static void merge(ProjectMetadata metadata, JSONObject options) { - // TODO Auto-generated method stub - - } } From 249fa4d8d54e12a56a576de695c41f33a9728297 Mon Sep 17 00:00:00 2001 From: Jacky Date: Thu, 26 Oct 2017 15:45:58 -0400 Subject: [PATCH 04/18] support metadata edit --- .../src/com/google/refine/ProjectManager.java | 2 +- .../com/google/refine/ProjectMetadata.java | 29 +++++++++++++++-- .../GetAllProjectMetadataCommand.java | 9 ++++++ .../google/refine/io/FileProjectManager.java | 2 +- .../webapp/modules/core/MOD-INF/controller.js | 7 +++-- .../modules/core/langs/translation-en.json | 6 ++++ .../modules/core/langs/translation-nb_NO.json | 1 - .../core/scripts/index/open-project-ui.js | 31 ++++++++++++++++++- .../core/styles/index/open-project-ui.less | 3 ++ 9 files changed, 81 insertions(+), 9 deletions(-) delete mode 100644 main/webapp/modules/core/langs/translation-nb_NO.json diff --git a/main/src/com/google/refine/ProjectManager.java b/main/src/com/google/refine/ProjectManager.java index 187899e66..48de19144 100644 --- a/main/src/com/google/refine/ProjectManager.java +++ b/main/src/com/google/refine/ProjectManager.java @@ -193,7 +193,7 @@ public abstract class ProjectManager { * @param projectId * @throws Exception */ - protected abstract void saveMetadata(ProjectMetadata metadata, long projectId) throws Exception; + public abstract void saveMetadata(ProjectMetadata metadata, long projectId) throws Exception; /** * Save project to the data store diff --git a/main/src/com/google/refine/ProjectMetadata.java b/main/src/com/google/refine/ProjectMetadata.java index a63867622..0e747fd8a 100644 --- a/main/src/com/google/refine/ProjectMetadata.java +++ b/main/src/com/google/refine/ProjectMetadata.java @@ -34,6 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine; import java.io.Serializable; +import java.lang.reflect.Field; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -114,13 +115,13 @@ public class ProjectMetadata implements Jsonizable { } writer.endObject(); - // write JSONArray to file directly + // write JSONArray directly if (_importOptionMetaData.length() > 0 ) { writer.key("importOptionMetaData"); writer.value(_importOptionMetaData); } - if ("save".equals(options.getProperty("mode"))) { + if (isSaveMode(options)) { writer.key("password"); writer.value(_password); writer.key("encoding"); writer.value(_encoding); @@ -131,10 +132,20 @@ public class ProjectMetadata implements Jsonizable { writer.endObject(); - if ("save".equals(options.getProperty("mode"))) { + if (isSaveMode(options)) { written = new Date(); } } + + public void writeWithoutOption(JSONWriter writer) + throws JSONException { + write(writer, + new Properties()); + } + + private boolean isSaveMode(Properties options) { + return "save".equals(options.getProperty("mode")); + } public boolean isDirty() { return written == null || _modified.after(written); @@ -369,5 +380,17 @@ public class ProjectMetadata implements Jsonizable { this._rowNumber = rowNumber; updateModified(); } + + public void setAnyField(String metaName, String valueString) { + Class metaClass = this.getClass(); + try { + Field metaField = metaClass.getDeclaredField("_" + metaName); + + metaField.set(this, valueString); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + // do nothing + e.printStackTrace(); + } + } } diff --git a/main/src/com/google/refine/commands/workspace/GetAllProjectMetadataCommand.java b/main/src/com/google/refine/commands/workspace/GetAllProjectMetadataCommand.java index 2d76b0055..c2f40128e 100644 --- a/main/src/com/google/refine/commands/workspace/GetAllProjectMetadataCommand.java +++ b/main/src/com/google/refine/commands/workspace/GetAllProjectMetadataCommand.java @@ -42,7 +42,9 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.json.JSONArray; import org.json.JSONException; +import org.json.JSONObject; import org.json.JSONWriter; import com.google.refine.ProjectManager; @@ -62,6 +64,7 @@ public class GetAllProjectMetadataCommand extends Command { Properties options = new Properties(); writer.object(); + writer.key("projects"); writer.object(); Map m = ProjectManager.singleton.getAllProjectMetadata(); @@ -73,6 +76,12 @@ public class GetAllProjectMetadataCommand extends Command { } } writer.endObject(); + + writer.key("customMetaDataColumns"); + JSONArray customMetaDataColumns = new JSONArray( + (String)ProjectManager.singleton.getPreferenceStore().get("userMetaData")); + writer.value(customMetaDataColumns); + writer.endObject(); } catch (JSONException e) { respondException(response, e); diff --git a/main/src/com/google/refine/io/FileProjectManager.java b/main/src/com/google/refine/io/FileProjectManager.java index 2fa42fc27..e1cac2ede 100644 --- a/main/src/com/google/refine/io/FileProjectManager.java +++ b/main/src/com/google/refine/io/FileProjectManager.java @@ -215,7 +215,7 @@ public class FileProjectManager extends ProjectManager { } @Override - protected void saveMetadata(ProjectMetadata metadata, long projectId) throws Exception { + public void saveMetadata(ProjectMetadata metadata, long projectId) throws Exception { File projectDir = getProjectDir(projectId); ProjectMetadataUtilities.save(metadata, projectDir); } diff --git a/main/webapp/modules/core/MOD-INF/controller.js b/main/webapp/modules/core/MOD-INF/controller.js index f8d4649c6..960981300 100644 --- a/main/webapp/modules/core/MOD-INF/controller.js +++ b/main/webapp/modules/core/MOD-INF/controller.js @@ -34,7 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. var html = "text/html"; var encoding = "UTF-8"; var ClientSideResourceManager = Packages.com.google.refine.ClientSideResourceManager; -var bundle = true; +var bundle = false; var templatedFiles = { // Requests with last path segments mentioned here @@ -68,9 +68,11 @@ function registerCommands() { RS.registerCommand(module, "get-project-metadata", new Packages.com.google.refine.commands.project.GetProjectMetadataCommand()); RS.registerCommand(module, "get-all-project-metadata", new Packages.com.google.refine.commands.workspace.GetAllProjectMetadataCommand()); + RS.registerCommand(module, "set-metaData", new Packages.com.google.refine.commands.project.SetProjectMetaDataCommand()); RS.registerCommand(module, "delete-project", new Packages.com.google.refine.commands.project.DeleteProjectCommand()); RS.registerCommand(module, "rename-project", new Packages.com.google.refine.commands.project.RenameProjectCommand()); + RS.registerCommand(module, "set-project-metadata", new Packages.com.google.refine.commands.project.SetProjectMetaDataCommand()); RS.registerCommand(module, "get-models", new Packages.com.google.refine.commands.project.GetModelsCommand()); RS.registerCommand(module, "get-rows", new Packages.com.google.refine.commands.row.GetRowsCommand()); @@ -350,7 +352,8 @@ function init() { "scripts/index/parser-interfaces/rdf-triples-parser-ui.js", "scripts/index/parser-interfaces/wikitext-parser-ui.js", - "scripts/reconciliation/recon-manager.js" // so that reconciliation functions are available to importers + "scripts/reconciliation/recon-manager.js", // so that reconciliation functions are available to importers + "scripts/index/edit-metadata-dialog.js" ] ); diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index c62863a34..19623f8e4 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -87,6 +87,12 @@ "open-proj": "Open Project", "name": "Name", "rename": "rename", + "edit-meta-data": "Edit meta data", + "creator": "Creator", + "contributors": "Contributors", + "subject": "Subject", + "description": "Description", + "row-number": "Row Number", "last-mod": "Last modified", "del-title": "Delete this project", "del-body": "Are you sure you want to delete project \"", diff --git a/main/webapp/modules/core/langs/translation-nb_NO.json b/main/webapp/modules/core/langs/translation-nb_NO.json deleted file mode 100644 index 0967ef424..000000000 --- a/main/webapp/modules/core/langs/translation-nb_NO.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/main/webapp/modules/core/scripts/index/open-project-ui.js b/main/webapp/modules/core/scripts/index/open-project-ui.js index 5d9d7004e..c01828abd 100644 --- a/main/webapp/modules/core/scripts/index/open-project-ui.js +++ b/main/webapp/modules/core/scripts/index/open-project-ui.js @@ -123,8 +123,23 @@ Refine.OpenProjectUI.prototype._renderProjects = function(data) { '' + '' + '' + + '' + '' + '' + + '' + + '' + + '' + + '' + + (function() { + var htmlDisplay = ""; + for (var n in data.customMetaDataColumns) { + if (data.customMetaDataColumns[n].display) { + htmlDisplay += ''; + } + } + + return htmlDisplay; + })() + '
'+$.i18n._('core-index-open')["last-mod"]+''+$.i18n._('core-index-open')["name"]+''+$.i18n._('core-index-open')["creator"]+''+$.i18n._('core-index-open')["subject"]+''+$.i18n._('core-index-open')["description"]+''+$.i18n._('core-index-open')["row-number"]+''+ data.customMetaDataColumns[n].name + '
' ).appendTo(container)[0]; @@ -189,7 +204,19 @@ Refine.OpenProjectUI.prototype._renderProjects = function(data) { }).appendTo( $(tr.insertCell(tr.cells.length)).css('width', '1%') ); - + + var editMetaDataLink = $('') + .text($.i18n._('core-index-open')["edit-meta-data"]) + .addClass("secondary") + .attr("href", "javascript:{}") + .css("visibility", "hidden") + .click(function() { + new EditMetadataDialog(project); + }) + .appendTo( + $(tr.insertCell(tr.cells.length)).css('width', '6%') + ); + $('
') .html(formatRelativeDate(project.date)) .addClass("last-modified") @@ -205,9 +232,11 @@ Refine.OpenProjectUI.prototype._renderProjects = function(data) { $(tr).mouseenter(function() { renameLink.css("visibility", "visible"); deleteLink.css("visibility", "visible"); + editMetaDataLink.css("visibility", "visible"); }).mouseleave(function() { renameLink.css("visibility", "hidden"); deleteLink.css("visibility", "hidden"); + editMetaDataLink.css("visibility", "hidden"); }); }; diff --git a/main/webapp/modules/core/styles/index/open-project-ui.less b/main/webapp/modules/core/styles/index/open-project-ui.less index 4a0e8796f..d2662207f 100644 --- a/main/webapp/modules/core/styles/index/open-project-ui.less +++ b/main/webapp/modules/core/styles/index/open-project-ui.less @@ -87,3 +87,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. opacity: 0.2; } +#metadata-body tr:nth-child(even) {background: #CCC} +#metadata-body tr:nth-child(odd) {background: #FFF} + From 6a47482ea4f7964333da723b524fb04ba7adc38a Mon Sep 17 00:00:00 2001 From: Jacky Date: Thu, 26 Oct 2017 15:47:24 -0400 Subject: [PATCH 05/18] support metadata edit --- .../project/SetProjectMetaDataCommand.java | 52 ++++++++++++ .../scripts/index/edit-metadata-dialog.js | 81 +++++++++++++++++++ .../scripts/project/edit-metadata-dialog.html | 11 +++ 3 files changed, 144 insertions(+) create mode 100644 main/src/com/google/refine/commands/project/SetProjectMetaDataCommand.java create mode 100644 main/webapp/modules/core/scripts/index/edit-metadata-dialog.js create mode 100644 main/webapp/modules/core/scripts/project/edit-metadata-dialog.html diff --git a/main/src/com/google/refine/commands/project/SetProjectMetaDataCommand.java b/main/src/com/google/refine/commands/project/SetProjectMetaDataCommand.java new file mode 100644 index 000000000..8cd2b175c --- /dev/null +++ b/main/src/com/google/refine/commands/project/SetProjectMetaDataCommand.java @@ -0,0 +1,52 @@ +package com.google.refine.commands.project; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONException; +import org.json.JSONTokener; +import org.json.JSONWriter; + +import com.google.refine.ProjectManager; +import com.google.refine.ProjectMetadata; +import com.google.refine.commands.Command; +import com.google.refine.model.Project; + +public class SetProjectMetaDataCommand extends Command { + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + Project project = request.getParameter("project") != null ? getProject(request) : null; + String metaName = request.getParameter("name"); + String valueString = request.getParameter("value"); + ProjectMetadata meta = null; + + if (project == null) { + respond(response, "{ \"code\" : \"error\", \"message\" : \"Project cannot be found\" }"); + return; + } + + meta = project.getMetadata(); + try { + response.setCharacterEncoding("UTF-8"); + response.setHeader("Content-Type", "application/json"); + JSONWriter writer = new JSONWriter(response.getWriter()); + + Object o = valueString == null ? null : new JSONTokener(valueString).nextValue(); + + meta.setAnyField(metaName, valueString); + ProjectManager.singleton.saveMetadata(meta, project.id); + + respond(response, "{ \"code\" : \"ok\" }"); + } catch (JSONException e) { + respondException(response, e); + } catch (Exception e) { + respondException(response, e); + } + } + +} diff --git a/main/webapp/modules/core/scripts/index/edit-metadata-dialog.js b/main/webapp/modules/core/scripts/index/edit-metadata-dialog.js new file mode 100644 index 000000000..c3b86b5c5 --- /dev/null +++ b/main/webapp/modules/core/scripts/index/edit-metadata-dialog.js @@ -0,0 +1,81 @@ + + +function EditMetadataDialog(metaData) { + this._metaDataUIs = []; + this._metaData = metaData; + + this._MetaDataUI = function(tr, key, value, project) { + var self = this; + + var td0 = tr.insertCell(0); + $(td0).text(key); + + var td1 = tr.insertCell(1); + $(td1).text((value !== null) ? value : ""); + + var td2 = tr.insertCell(2); + + $('