2010-09-22 19:04:10 +02:00
|
|
|
package com.google.refine.expr.functions;
|
2010-05-05 01:24:48 +02:00
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONWriter;
|
|
|
|
|
2010-09-22 19:04:10 +02:00
|
|
|
import com.google.refine.ProjectManager;
|
|
|
|
import com.google.refine.InterProjectModel.ProjectJoin;
|
|
|
|
import com.google.refine.expr.EvalError;
|
|
|
|
import com.google.refine.expr.WrappedCell;
|
2010-10-07 07:19:35 +02:00
|
|
|
import com.google.refine.grel.ControlFunctionRegistry;
|
|
|
|
import com.google.refine.grel.Function;
|
2010-09-22 19:04:10 +02:00
|
|
|
import com.google.refine.model.Project;
|
2010-05-05 01:24:48 +02:00
|
|
|
|
|
|
|
public class Cross implements Function {
|
|
|
|
|
|
|
|
public Object call(Properties bindings, Object[] args) {
|
|
|
|
if (args.length == 3) {
|
|
|
|
// from project is implied
|
|
|
|
|
|
|
|
Object wrappedCell = args[0]; // from cell
|
|
|
|
Object toProjectName = args[1];
|
|
|
|
Object toColumnName = args[2];
|
|
|
|
|
|
|
|
if (wrappedCell != null && wrappedCell instanceof WrappedCell &&
|
|
|
|
toProjectName != null && toProjectName instanceof String &&
|
|
|
|
toColumnName != null && toColumnName instanceof String) {
|
|
|
|
|
|
|
|
ProjectJoin join = ProjectManager.singleton.getInterProjectModel().getJoin(
|
|
|
|
ProjectManager.singleton.getProjectMetadata(
|
|
|
|
((Project) bindings.get("project")).id).getName(),
|
|
|
|
((WrappedCell) wrappedCell).columnName,
|
|
|
|
(String) toProjectName,
|
|
|
|
(String) toColumnName
|
|
|
|
);
|
|
|
|
|
|
|
|
return join.getRows(((WrappedCell) wrappedCell).cell.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a cell, a project name to join with, and a column name in that project");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void write(JSONWriter writer, Properties options)
|
|
|
|
throws JSONException {
|
|
|
|
|
|
|
|
writer.object();
|
|
|
|
writer.key("description"); writer.value("TODO");
|
|
|
|
writer.key("params"); writer.value("cell c, string projectName, string columnName");
|
|
|
|
writer.key("returns"); writer.value("array");
|
|
|
|
writer.endObject();
|
|
|
|
}
|
|
|
|
}
|