diff --git a/main/src/com/google/refine/ProjectManager.java b/main/src/com/google/refine/ProjectManager.java index cf8a1cdd9..9b18f2d41 100644 --- a/main/src/com/google/refine/ProjectManager.java +++ b/main/src/com/google/refine/ProjectManager.java @@ -139,6 +139,7 @@ public abstract class ProjectManager { _projectsMetadata.put(project.id, projectMetadata); if (_projectsTags == null) { _projectsTags = new HashMap(); +<<<<<<< Upstream, based on origin/master } String[] tags = projectMetadata.getTags(); if (tags != null) { @@ -148,6 +149,16 @@ public abstract class ProjectManager { } else { _projectsTags.put(tag, 1); } +======= + String[] tags = projectMetadata.getTags(); + if (tags != null) { + for (String tag : tags) { + if (_projectsTags.containsKey(tag)) { + _projectsTags.put(tag, _projectsTags.get(tag) + 1); + } else { + _projectsTags.put(tag, 1); + } +>>>>>>> 529b6bd Modified tags in metadata dialog and moved column right to name } } } diff --git a/main/src/com/google/refine/ProjectMetadata.java b/main/src/com/google/refine/ProjectMetadata.java index 040b878e2..49ddb2281 100644 --- a/main/src/com/google/refine/ProjectMetadata.java +++ b/main/src/com/google/refine/ProjectMetadata.java @@ -57,31 +57,32 @@ import com.google.refine.util.JSONUtilities; import com.google.refine.util.ParsingUtilities; public class ProjectMetadata implements Jsonizable { - private final Date _created; - private Date _modified; - private Date written = null; - private String _name = ""; - private String _password = ""; - private String _encoding = ""; - private int _encodingConfidence; - + private final Date _created; + private Date _modified; + private Date written = null; + private String _name = ""; + private String _password = ""; + + private String _encoding = ""; + private int _encodingConfidence; + private String[] _tags = new String[0]; - + private String _creator = ""; private String _contributors = ""; - private String _subject = ""; // Several refine projects may be linked - private String _description = ""; // free form of comment - private int _rowCount; // at the creation. Essential for cleaning old projects too heavy - + private String _subject = ""; // Several refine projects may be linked + private String _description = ""; // free form of comment + private int _rowCount; // 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(); - + // user metadata - private JSONArray _userMetadata = new JSONArray();; - - private Map _customMetadata = new HashMap(); - private PreferenceStore _preferenceStore = new PreferenceStore(); + private JSONArray _userMetadata = new JSONArray();; + + private Map _customMetadata = new HashMap(); + private PreferenceStore _preferenceStore = new PreferenceStore(); private final static Logger logger = LoggerFactory.getLogger("project_metadata"); @@ -100,70 +101,81 @@ public class ProjectMetadata implements Jsonizable { _modified = modified; _name = name; } - + @Override public void write(JSONWriter writer, Properties options) throws JSONException { writer.object(); - 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("rowCount"); writer.value(_rowCount); - - writer.key("customMetadata"); writer.object(); + writer.key("name"); + writer.value(_name); + writer.key("tags"); + writer.array(); + for (String tag : _tags) { + writer.value(tag); + } + writer.endArray(); + 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("rowCount"); + writer.value(_rowCount); + + writer.key("customMetadata"); + writer.object(); for (String key : _customMetadata.keySet()) { Serializable value = _customMetadata.get(key); writer.key(key); writer.value(value); } writer.endObject(); - - writer.key("tags"); - writer.array(); - for (String tag : _tags) { - writer.value(tag); - } - writer.endArray(); - - // write JSONArray directly - if (_importOptionMetadata.length() > 0 ) { - writer.key("importOptionMetadata"); + + // write JSONArray directly + if (_importOptionMetadata.length() > 0) { + writer.key("importOptionMetadata"); writer.value(_importOptionMetadata); } - + // write user metadata in {name, value, display} form: if (_userMetadata.length() > 0) { writer.key(PreferenceStore.USER_METADATA_KEY); writer.value(_userMetadata); } - + if (isSaveMode(options)) { - writer.key("password"); writer.value(_password); + writer.key("password"); + writer.value(_password); - writer.key("encoding"); writer.value(_encoding); - writer.key("encodingConfidence"); writer.value(_encodingConfidence); + writer.key("encoding"); + writer.value(_encoding); + writer.key("encodingConfidence"); + writer.value(_encodingConfidence); - writer.key("preferences"); _preferenceStore.write(writer, options); + writer.key("preferences"); + _preferenceStore.write(writer, options); } - + writer.endObject(); - + if (isSaveMode(options)) { written = new Date(); } } - + public void writeWithoutOption(JSONWriter writer) throws JSONException { - write(writer, - new Properties()); + write(writer, new Properties()); } - + private boolean isSaveMode(Properties options) { return "save".equals(options.getProperty("mode")); } @@ -171,17 +183,21 @@ public class ProjectMetadata implements Jsonizable { public boolean isDirty() { return written == null || _modified.after(written); } - - public void write(JSONWriter jsonWriter) throws JSONException { + + public void write(JSONWriter jsonWriter) + throws JSONException { write(jsonWriter, false); } - + /** - * @param jsonWriter writer to save metadatea to - * @param onlyIfDirty true to not write unchanged metadata + * @param jsonWriter + * writer to save metadatea to + * @param onlyIfDirty + * true to not write unchanged metadata * @throws JSONException */ - public void write(JSONWriter jsonWriter, boolean onlyIfDirty) throws JSONException { + public void write(JSONWriter jsonWriter, boolean onlyIfDirty) + throws JSONException { if (!onlyIfDirty || isDirty()) { Properties options = new Properties(); options.setProperty("mode", "save"); @@ -189,9 +205,9 @@ public class ProjectMetadata implements Jsonizable { write(jsonWriter, options); } } - + static public ProjectMetadata loadFromJSON(JSONObject obj) { - // TODO: Is this correct? It's using modified date for creation date + // TODO: Is this correct? It's using modified date for creation date ProjectMetadata pm = new ProjectMetadata(JSONUtilities.getDate(obj, "modified", new Date())); pm._modified = JSONUtilities.getDate(obj, "modified", new Date()); @@ -200,15 +216,15 @@ 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._rowCount = JSONUtilities.getInt(obj, "rowCount", 0); - + pm._tags = JSONUtilities.getStringArray(obj, "tags"); - + if (obj.has("preferences") && !obj.isNull("preferences")) { try { pm._preferenceStore.load(obj.getJSONObject("preferences")); @@ -216,20 +232,19 @@ public class ProjectMetadata implements Jsonizable { logger.error(ExceptionUtils.getFullStackTrace(e)); } } - + if (obj.has("expressions") && !obj.isNull("expressions")) { // backward compatibility try { - ((TopList) pm._preferenceStore.get("scripting.expressions")) - .load(obj.getJSONArray("expressions")); + ((TopList) pm._preferenceStore.get("scripting.expressions")).load(obj.getJSONArray("expressions")); } catch (JSONException e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } } - + if (obj.has("customMetadata") && !obj.isNull("customMetadata")) { try { JSONObject obj2 = obj.getJSONObject("customMetadata"); - + @SuppressWarnings("unchecked") Iterator keys = obj2.keys(); while (keys.hasNext()) { @@ -243,7 +258,7 @@ public class ProjectMetadata implements Jsonizable { logger.error(ExceptionUtils.getFullStackTrace(e)); } } - + if (obj.has("importOptionMetadata") && !obj.isNull("importOptionMetadata")) { try { JSONArray jsonArray = obj.getJSONArray("importOptionMetadata"); @@ -252,7 +267,7 @@ public class ProjectMetadata implements Jsonizable { logger.error(ExceptionUtils.getFullStackTrace(e)); } } - + if (obj.has(PreferenceStore.USER_METADATA_KEY) && !obj.isNull(PreferenceStore.USER_METADATA_KEY)) { try { JSONArray jsonArray = obj.getJSONArray(PreferenceStore.USER_METADATA_KEY); @@ -260,13 +275,13 @@ public class ProjectMetadata implements Jsonizable { } catch (JSONException e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } - } - + } + pm.written = new Date(); // Mark it as not needing writing until modified - + return pm; } - + static protected void preparePreferenceStore(PreferenceStore ps) { ProjectManager.preparePreferenceStore(ps); // Any project specific preferences? @@ -308,30 +323,29 @@ public class ProjectMetadata implements Jsonizable { public int getEncodingConfidence() { return _encodingConfidence; } - + public void setTags(String[] tags) { if (tags != null) { - List tmpTags = new ArrayList(tags.length); - for (String tag : tags) { - if (tag != null) { - String trimmedTag = tag.trim(); + List tmpTags = new ArrayList(tags.length); + for (String tag : tags) { + if (tag != null) { + String trimmedTag = tag.trim(); - if (!trimmedTag.isEmpty()) { - tmpTags.add(trimmedTag); - } + if (!trimmedTag.isEmpty()) { + tmpTags.add(trimmedTag); + } + } } - } - this._tags = tmpTags.toArray(new String[tmpTags.size()]); + this._tags = tmpTags.toArray(new String[tmpTags.size()]); } else { - this._tags = tags; + this._tags = tags; } updateModified(); - } + } - public String[] getTags() { - if (_tags == null) - this._tags = new String[0]; + public String[] getTags() { + if (_tags == null) this._tags = new String[0]; return _tags; } @@ -355,11 +369,11 @@ public class ProjectMetadata implements Jsonizable { public PreferenceStore getPreferenceStore() { return _preferenceStore; } - + public Serializable getCustomMetadata(String key) { return _customMetadata.get(key); } - + public void setCustomMetadata(String key, Serializable value) { if (value == null) { _customMetadata.remove(key); @@ -368,87 +382,75 @@ 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(); } - public String getCreator() { return _creator; } - public void setCreator(String creator) { this._creator = creator; updateModified(); } - public String getContributors() { return _contributors; } - public void setContributors(String contributors) { this._contributors = contributors; updateModified(); } - public String getSubject() { return _subject; } - public void setSubject(String subject) { this._subject = subject; updateModified(); } - public String getDescription() { return _description; } - public void setDescription(String description) { this._description = description; updateModified(); } - public int getRowCount() { return _rowCount; } - public void setRowCount(int rowCount) { this._rowCount = rowCount; updateModified(); } - public JSONArray getUserMetadata() { return _userMetadata; } - public void setUserMetadata(JSONArray userMetadata) { this._userMetadata = userMetadata; } - private void updateUserMetadata(String metaName, String valueString) { + private void updateUserMetadata(String metaName, String valueString) { for (int i = 0; i < _userMetadata.length(); i++) { try { JSONObject obj = _userMetadata.getJSONObject(i); @@ -460,18 +462,21 @@ public class ProjectMetadata implements Jsonizable { } } } - - public void setAnyField(String metaName, String valueString) { + + public void setAnyField(String metaName, String valueString) { Class metaClass = this.getClass(); try { Field metaField = metaClass.getDeclaredField("_" + metaName); - - metaField.set(this, valueString); + if (metaName.equals("tags")) { + metaField.set(this, valueString.split(",")); + } else { + metaField.set(this, valueString); + } } catch (NoSuchFieldException e) { updateUserMetadata(metaName, valueString); } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } } - + } diff --git a/main/tests/server/src/com/google/refine/tests/ProjectManagerTests.java b/main/tests/server/src/com/google/refine/tests/ProjectManagerTests.java index b266b5f57..305893e57 100644 --- a/main/tests/server/src/com/google/refine/tests/ProjectManagerTests.java +++ b/main/tests/server/src/com/google/refine/tests/ProjectManagerTests.java @@ -94,9 +94,15 @@ public class ProjectManagerTests extends RefineTest { SUT.registerProject(project, metadata); +<<<<<<< Upstream, based on origin/master AssertProjectRegistered(); verify(metadata, times(1)).getTags(); +======= + AssertProjectRegistered(); + verify(metadata, times(1)).getTags(); + +>>>>>>> 529b6bd Modified tags in metadata dialog and moved column right to name verifyNoMoreInteractions(project); verifyNoMoreInteractions(metadata); } @@ -121,7 +127,11 @@ public class ProjectManagerTests extends RefineTest { this.verifySaveTimeCompared(1); verify(SUT, times(1)).saveProject(project); verify(metadata, times(1)).getTags(); +<<<<<<< Upstream, based on origin/master +======= + +>>>>>>> 529b6bd Modified tags in metadata dialog and moved column right to name //ensure end verifyNoMoreInteractions(project); verifyNoMoreInteractions(metadata); diff --git a/main/tests/server/src/com/google/refine/tests/browsing/facets/TextSearchFacetTests.java b/main/tests/server/src/com/google/refine/tests/browsing/facets/TextSearchFacetTests.java index ad6876fe5..345ee166b 100644 --- a/main/tests/server/src/com/google/refine/tests/browsing/facets/TextSearchFacetTests.java +++ b/main/tests/server/src/com/google/refine/tests/browsing/facets/TextSearchFacetTests.java @@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.google.refine.tests.model; +package com.google.refine.tests.browsing.facets; import static org.mockito.Mockito.mock; diff --git a/main/tests/server/src/com/google/refine/tests/operations/cell/JoinMultiValuedCellsTests.java b/main/tests/server/src/com/google/refine/tests/operations/cell/JoinMultiValuedCellsTests.java index 80d0de178..aa32ef2b0 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/cell/JoinMultiValuedCellsTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/cell/JoinMultiValuedCellsTests.java @@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.google.refine.tests.model; +package com.google.refine.tests.operations.cell; import static org.mockito.Mockito.mock; diff --git a/main/webapp/modules/core/scripts/index/default-importing-controller/controller.js b/main/webapp/modules/core/scripts/index/default-importing-controller/controller.js index 6478327bd..4fd3704ad 100644 --- a/main/webapp/modules/core/scripts/index/default-importing-controller/controller.js +++ b/main/webapp/modules/core/scripts/index/default-importing-controller/controller.js @@ -351,7 +351,14 @@ Refine.TagsManager._getAllProjectTags = function() { }); array.map(function(item){ +<<<<<<< Upstream, based on origin/master self.allProjectTags.push(item); +======= + self.allProjectTags.push(item); + }); + }, + async : false +>>>>>>> 529b6bd Modified tags in metadata dialog and moved column right to name }); }, async : false diff --git a/main/webapp/modules/core/scripts/index/edit-metadata-dialog.js b/main/webapp/modules/core/scripts/index/edit-metadata-dialog.js index 80ec5e4d5..9c421f5de 100644 --- a/main/webapp/modules/core/scripts/index/edit-metadata-dialog.js +++ b/main/webapp/modules/core/scripts/index/edit-metadata-dialog.js @@ -21,11 +21,38 @@ function EditMetadataDialog(metaData, targetRowElem) { var td2 = tr.insertCell(2); + if(key==="tags"){ + $('