diff --git a/main/src/com/google/refine/InterProjectModel.java b/main/src/com/google/refine/InterProjectModel.java index 295042612..eb69aec47 100644 --- a/main/src/com/google/refine/InterProjectModel.java +++ b/main/src/com/google/refine/InterProjectModel.java @@ -97,13 +97,13 @@ public class InterProjectModel { * @param toColumn * @return */ - public ProjectJoin getJoin(String fromProject, String fromColumn, String toProject, String toColumn) { + public ProjectJoin getJoin(Long fromProject, String fromColumn, Long toProject, String toColumn) { String key = fromProject + ";" + fromColumn + ";" + toProject + ";" + toColumn; if (!_joins.containsKey(key)) { ProjectJoin join = new ProjectJoin( - ProjectManager.singleton.getProjectID(fromProject), + fromProject, fromColumn, - ProjectManager.singleton.getProjectID(toProject), + toProject, toColumn ); diff --git a/main/src/com/google/refine/ProjectManager.java b/main/src/com/google/refine/ProjectManager.java index 66f2e6dcd..89070ac29 100644 --- a/main/src/com/google/refine/ProjectManager.java +++ b/main/src/com/google/refine/ProjectManager.java @@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine; +import com.google.refine.util.GetProjectIDException; import java.io.IOException; import java.io.InputStream; import java.time.LocalDateTime; @@ -383,15 +384,26 @@ public abstract class ProjectManager { * @param name * The name of the project * @return - * The id of the project, or -1 if it cannot be found + * The id of the project + * @throws GetProjectIDException + * If no unique project is found with the given name */ - public long getProjectID(String name) { + public long getProjectID(String name) throws GetProjectIDException { + Integer c = 0; + Long id = 0L; for (Entry entry : _projectsMetadata.entrySet()) { if (entry.getValue().getName().equals(name)) { - return entry.getKey(); + id = entry.getKey(); + c += 1; } } - return -1; + if (c == 1) { + return id; + } else if (c == 0) { + throw new GetProjectIDException("Unable to find project with name: " + name); + } else { + throw new GetProjectIDException(c + " projects found with name: " + name); + } } /** diff --git a/main/src/com/google/refine/expr/functions/Cross.java b/main/src/com/google/refine/expr/functions/Cross.java index b9ed764f2..07ecee5da 100644 --- a/main/src/com/google/refine/expr/functions/Cross.java +++ b/main/src/com/google/refine/expr/functions/Cross.java @@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.expr.functions; +import com.google.refine.util.GetProjectIDException; import java.util.Properties; import com.google.refine.InterProjectModel.ProjectJoin; @@ -51,17 +52,27 @@ public class Cross implements Function { // 1st argument can take either value or cell(for backward compatibility) Object v = args[0]; Object toProjectName = args[1]; - Object toColumnName = args[2]; + Object toColumnName = args[2]; + Long toProjectID; if (v != null && ( v instanceof String || v instanceof WrappedCell ) && toProjectName != null && toProjectName instanceof String && toColumnName != null && toColumnName instanceof String) { - + try { + toProjectID = ProjectManager.singleton.getProjectID((String) toProjectName); + } catch (GetProjectIDException e){ + return new EvalError(e.getMessage()); + } ProjectJoin join = ProjectManager.singleton.getInterProjectModel().getJoin( - ProjectManager.singleton.getProjectMetadata(((Project) bindings.get("project")).id).getName(), + // getJoin(Long fromProject, String fromColumn, Long toProject, String toColumn) { + // source project name + (Long) ((Project) bindings.get("project")).id, + // source column name (String) bindings.get("columnName"), - (String) toProjectName, + // target project name + toProjectID, + // target column name (String) toColumnName ); if(v instanceof String) {