Refactor cross function to be more robust & improve diagnostics on fail
This commit is contained in:
parent
ff888d239b
commit
ae5f72a8df
@ -97,13 +97,13 @@ public class InterProjectModel {
|
|||||||
* @param toColumn
|
* @param toColumn
|
||||||
* @return
|
* @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;
|
String key = fromProject + ";" + fromColumn + ";" + toProject + ";" + toColumn;
|
||||||
if (!_joins.containsKey(key)) {
|
if (!_joins.containsKey(key)) {
|
||||||
ProjectJoin join = new ProjectJoin(
|
ProjectJoin join = new ProjectJoin(
|
||||||
ProjectManager.singleton.getProjectID(fromProject),
|
fromProject,
|
||||||
fromColumn,
|
fromColumn,
|
||||||
ProjectManager.singleton.getProjectID(toProject),
|
toProject,
|
||||||
toColumn
|
toColumn
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
package com.google.refine;
|
package com.google.refine;
|
||||||
|
|
||||||
|
import com.google.refine.util.GetProjectIDException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -383,15 +384,26 @@ public abstract class ProjectManager {
|
|||||||
* @param name
|
* @param name
|
||||||
* The name of the project
|
* The name of the project
|
||||||
* @return
|
* @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<Long, ProjectMetadata> entry : _projectsMetadata.entrySet()) {
|
for (Entry<Long, ProjectMetadata> entry : _projectsMetadata.entrySet()) {
|
||||||
if (entry.getValue().getName().equals(name)) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
package com.google.refine.expr.functions;
|
package com.google.refine.expr.functions;
|
||||||
|
|
||||||
|
import com.google.refine.util.GetProjectIDException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import com.google.refine.InterProjectModel.ProjectJoin;
|
import com.google.refine.InterProjectModel.ProjectJoin;
|
||||||
@ -52,16 +53,26 @@ public class Cross implements Function {
|
|||||||
Object v = args[0];
|
Object v = args[0];
|
||||||
Object toProjectName = args[1];
|
Object toProjectName = args[1];
|
||||||
Object toColumnName = args[2];
|
Object toColumnName = args[2];
|
||||||
|
Long toProjectID;
|
||||||
|
|
||||||
if (v != null &&
|
if (v != null &&
|
||||||
( v instanceof String || v instanceof WrappedCell ) &&
|
( v instanceof String || v instanceof WrappedCell ) &&
|
||||||
toProjectName != null && toProjectName instanceof String &&
|
toProjectName != null && toProjectName instanceof String &&
|
||||||
toColumnName != null && toColumnName 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(
|
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) bindings.get("columnName"),
|
||||||
(String) toProjectName,
|
// target project name
|
||||||
|
toProjectID,
|
||||||
|
// target column name
|
||||||
(String) toColumnName
|
(String) toColumnName
|
||||||
);
|
);
|
||||||
if(v instanceof String) {
|
if(v instanceof String) {
|
||||||
|
Loading…
Reference in New Issue
Block a user