Merge pull request #1342 from jackyq2015/feature/metadata

fix the row count refresh issue.  We'll work on adding a Delete Metadata option in the next milestone.
This commit is contained in:
Thad Guidry 2017-11-18 08:30:32 -06:00 committed by GitHub
commit daca1836e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 74 deletions

View File

@ -44,7 +44,11 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.tools.tar.TarOutputStream;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -371,12 +375,94 @@ public abstract class ProjectManager {
return -1;
}
/**
* A valid user meta data definition should have name and display property
* @param placeHolderJsonObj
* @return
*/
private boolean isValidUserMetadataDefinition(JSONObject placeHolderJsonObj) {
return (placeHolderJsonObj != null &&
placeHolderJsonObj.has("name") &&
placeHolderJsonObj.has("display"));
}
public void mergeEmptyUserMetadata(ProjectMetadata metadata) {
if (metadata == null)
return;
// place holder
JSONArray userMetadataPreference = null;
// actual metadata for project
JSONArray jsonObjArray = metadata.getUserMetadata();
initDisplay(jsonObjArray);
try {
String userMeta = (String)_preferenceStore.get(PreferenceStore.USER_METADATA_KEY);
if (userMeta == null)
return;
userMetadataPreference = new JSONArray(userMeta);
} catch (JSONException e1) {
logger.warn("wrong definition of userMetadata format. Please use form [{\"name\": \"client name\", \"display\":true}, {\"name\": \"progress\", \"display\":false}]");
logger.error(ExceptionUtils.getFullStackTrace(e1));
}
for (int index = 0; index < userMetadataPreference.length(); index++) {
try {
boolean found = false;
JSONObject placeHolderJsonObj = userMetadataPreference.getJSONObject(index);
if (!isValidUserMetadataDefinition(placeHolderJsonObj)) {
logger.warn("Skipped invalid user metadata definition" + placeHolderJsonObj.toString());
continue;
}
for (int i = 0; i < jsonObjArray.length(); i++) {
JSONObject jsonObj = jsonObjArray.getJSONObject(i);
if (jsonObj.getString("name").equals(placeHolderJsonObj.getString("name"))) {
found = true;
jsonObj.put("display", placeHolderJsonObj.get("display"));
break;
}
}
if (!found) {
placeHolderJsonObj.put("value", "");
metadata.getUserMetadata().put(placeHolderJsonObj);
logger.info("Put the placeholder {} for project {}",
placeHolderJsonObj.getString("name"),
metadata.getName());
}
} catch (JSONException e) {
logger.warn("Exception when mergeEmptyUserMetadata",e);
}
}
}
/**
* Gets all the project Metadata currently held in memory
* honor the meta data preference
* @param jsonObjArray
*/
private void initDisplay(JSONArray jsonObjArray) {
for (int index = 0; index < jsonObjArray.length(); index++) {
try {
JSONObject projectMetaJsonObj = jsonObjArray.getJSONObject(index);
projectMetaJsonObj.put("display", false);
} catch (JSONException e) {
logger.error(ExceptionUtils.getFullStackTrace(e));
}
}
}
/**
* Gets all the project Metadata currently held in memory.
* @return
*/
public Map<Long, ProjectMetadata> getAllProjectMetadata() {
for(Project project : _projects.values()) {
mergeEmptyUserMetadata(project.getMetadata());
}
return _projectsMetadata;
}

View File

@ -178,6 +178,9 @@ public class GetRowsCommand extends Command {
if (callback != null) {
writer.write(")");
}
// metadata refresh for row mode and record mode
project.getMetadata().setRowCount(project.rows.size());
} catch (Exception e) {
respondException(response, e);
}

View File

@ -44,7 +44,6 @@ import java.io.OutputStream;
import java.util.Properties;
import java.util.zip.GZIPInputStream;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarInputStream;
import org.apache.tools.tar.TarOutputStream;
@ -60,7 +59,6 @@ import com.google.refine.ProjectManager;
import com.google.refine.ProjectMetadata;
import com.google.refine.history.HistoryEntryManager;
import com.google.refine.model.Project;
import com.google.refine.preference.PreferenceStore;
import com.google.refine.preference.TopList;
@ -403,72 +401,6 @@ public class FileProjectManager extends ProjectManager {
return found;
}
public void mergeEmptyUserMetadata(ProjectMetadata metadata) {
if (metadata == null)
return;
// place holder
JSONArray userMetadataPreference = null;
// actual metadata for project
JSONArray jsonObjArray = metadata.getUserMetadata();
try {
String userMeta = (String)_preferenceStore.get(PreferenceStore.USER_METADATA_KEY);
if (userMeta == null)
return;
userMetadataPreference = new JSONArray(userMeta);
} catch (JSONException e1) {
logger.error(ExceptionUtils.getFullStackTrace(e1));
}
if (userMetadataPreference == null) {
logger.warn("wrong definition of userMetadata format. Please use form [{\"name\": \"client name\", \"display\":true}, {\"name\": \"progress\", \"display\":false}]");
return;
}
for (int index = 0; index < userMetadataPreference.length(); index++) {
try {
boolean found = false;
JSONObject placeHolderJsonObj = userMetadataPreference.getJSONObject(index);
if (!isValidUserMetadataDefinition(placeHolderJsonObj)) {
logger.warn("Skipped invalid user metadata definition" + placeHolderJsonObj.toString());
continue;
}
for (int i = 0; i < jsonObjArray.length(); i++) {
JSONObject jsonObj = jsonObjArray.getJSONObject(i);
if (jsonObj.getString("name").equals(placeHolderJsonObj.getString("name"))) {
found = true;
jsonObj.put("display", placeHolderJsonObj.get("display"));
break;
}
}
if (!found) {
placeHolderJsonObj.put("value", "");
metadata.getUserMetadata().put(placeHolderJsonObj);
logger.info("Put the placeholder {} for project {}",
placeHolderJsonObj.getString("name"),
metadata.getName());
}
} catch (JSONException e) {
logger.warn("Exception when mergeEmptyUserMetadata",e);
}
}
}
/**
* A valid user meta data definition should have name and display property
* @param placeHolderJsonObj
* @return
*/
private boolean isValidUserMetadataDefinition(JSONObject placeHolderJsonObj) {
return (placeHolderJsonObj != null &&
placeHolderJsonObj.has("name") &&
placeHolderJsonObj.has("display"));
}
protected void recover() {
boolean recovered = false;
for (File file : _workspaceDir.listFiles()) {

View File

@ -7,8 +7,9 @@ function EditMetadataDialog(metaData, targetRowElem) {
this._MetadataUI = function(tr, key, value, project) {
var self = this;
if (key === "date")
if (key === "date") {
return;
}
var td0 = tr.insertCell(0);

View File

@ -110,17 +110,17 @@ Refine.OpenProjectUI.prototype._renderProjects = function(data) {
project.date = moment(project.modified).format('YYYY-MM-DD HH:mm A');
if (typeof project.userMetadata !== "undefined") {
for (var n in data.customMetadataColumns) {
for (var m in data.customMetadataColumns) {
var found = false;
for(var i = 0; i < project.userMetadata.length; i++) {
if (project.userMetadata[i].name === data.customMetadataColumns[n].name) {
if (project.userMetadata[i].name === data.customMetadataColumns[m].name) {
found = true;
break;
}
if (!found) {
project.userMetadata.push({
name: data.customMetadataColumns[n].name,
dispay: data.customMetadataColumns[n].display,
name: data.customMetadataColumns[m].name,
dispay: data.customMetadataColumns[m].display,
value: ""
});
}