use of com.google.refine.LookupCacheManager.ProjectLookup in project OpenRefine by OpenRefine.
the class Cross method call.
@Override
public Object call(Properties bindings, Object[] args) {
if (1 <= args.length && args.length <= 3) {
// 1st argument can take either value or cell(for backward compatibility)
Object v = args[0];
// if 2nd argument is omitted or set to "", use the current project name
Object targetProjectName = "";
boolean isCurrentProject = false;
if (args.length < 2 || args[1].equals("")) {
isCurrentProject = true;
} else {
targetProjectName = args[1];
}
// if 3rd argument is omitted or set to "", use the index column
Object targetColumnName = args.length < 3 || args[2].equals("") ? INDEX_COLUMN_NAME : args[2];
long targetProjectID;
ProjectLookup lookup;
if (v != null && targetProjectName instanceof String && targetColumnName instanceof String) {
try {
targetProjectID = isCurrentProject ? ((Project) bindings.get("project")).id : ProjectManager.singleton.getProjectID((String) targetProjectName);
} catch (GetProjectIDException e) {
return new EvalError(e.getMessage());
}
try {
lookup = ProjectManager.singleton.getLookupCacheManager().getLookup(targetProjectID, (String) targetColumnName);
} catch (LookupException e) {
return new EvalError(e.getMessage());
}
if (v instanceof WrappedCell) {
return lookup.getRows(((WrappedCell) v).cell.value);
} else {
return lookup.getRows(v);
}
}
}
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a cell or value, a project name to look up (optional), and a column name in that project (optional)");
}
Aggregations