/** * If the last element in the path is a reference or collection return the ClassDescriptor that * the reference or collection references. If the path has one element (eg. "Employee"), * return its ClassDescriptor. If the last element in the path is an attribute, return null. * @return the ClassDescriptor */ public ClassDescriptor getEndClassDescriptor() { if (getEndFieldDescriptor() == null) { return getStartClassDescriptor(); } if (!getEndFieldDescriptor().isAttribute()) { if (getEndFieldDescriptor().isCollection()) { CollectionDescriptor collDesc = (CollectionDescriptor) getEndFieldDescriptor(); return collDesc.getReferencedClassDescriptor(); } if (getEndFieldDescriptor().isReference()) { ReferenceDescriptor refDesc = (ReferenceDescriptor) getEndFieldDescriptor(); return refDesc.getReferencedClassDescriptor(); } } return null; }
/** * If the last element in the path is a reference or collection return the ClassDescriptor that * the reference or collection references. If the path has one element (eg. "Employee"), * return its ClassDescriptor. If the last element in the path is an attribute, return null. * @return the ClassDescriptor */ public ClassDescriptor getEndClassDescriptor() { if (getEndFieldDescriptor() == null) { return getStartClassDescriptor(); } if (!getEndFieldDescriptor().isAttribute()) { if (getEndFieldDescriptor().isCollection()) { CollectionDescriptor collDesc = (CollectionDescriptor) getEndFieldDescriptor(); return collDesc.getReferencedClassDescriptor(); } if (getEndFieldDescriptor().isReference()) { ReferenceDescriptor refDesc = (ReferenceDescriptor) getEndFieldDescriptor(); return refDesc.getReferencedClassDescriptor(); } } return null; }
/** * Constructs a new ResultCell object * @param imObj the InterMineObject or SimpleObject to wrap * @param path the Path * @param isKeyField should be true if this is an identifying field */ public ResultElement(FastPathObject imObj, Path path, boolean isKeyField) { this.imObj = imObj; this.keyField = isKeyField; this.path = path; if (imObj != null) { try { field = imObj.getFieldValue(path.getEndFieldDescriptor().getName()); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } else { field = null; } }
/** * Constructs a new ResultCell object * @param imObj the InterMineObject or SimpleObject to wrap * @param path the Path * @param isKeyField should be true if this is an identifying field */ public ResultElement(FastPathObject imObj, Path path, boolean isKeyField) { this.imObj = imObj; this.keyField = isKeyField; this.path = path; if (imObj != null) { try { field = imObj.getFieldValue(path.getEndFieldDescriptor().getName()); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } else { field = null; } }
@Override public Void visitLeft(ResultCell a) { System.out.printf(spacer + "%s: %s\n", a.getPath().getEndFieldDescriptor().getName(), a.getField()); return null; }
private void addColumnsInternal(List<Path> paths) { List<String> types = new ArrayList<String>(); int i = columns.size(); for (Path columnPath : paths) { String type = TypeUtil.unqualifiedName(columnPath.getLastClassDescriptor() .getName()); Class typeCls = columnPath.getLastClassDescriptor().getType(); String columnDescription = pathQuery.getGeneratedPathDescription(columnPath. toStringNoConstraints()); Column column; if (columnDescription.equals(columnPath.toStringNoConstraints())) { column = new Column(columnPath, i, typeCls); } else { column = new Column(columnPath, columnDescription, i, typeCls); } if (!types.contains(column.getColumnId())) { String fieldName = columnPath.getEndFieldDescriptor().getName(); boolean isKeyField = ClassKeyHelper.isKeyField(classKeys, type, fieldName); if (isKeyField) { column.setSelectable(true); types.add(column.getColumnId()); } } columns.add(column); i++; } }
private void addColumnsInternal(List<Path> paths) { List<String> types = new ArrayList<String>(); int i = columns.size(); for (Path columnPath : paths) { String type = TypeUtil.unqualifiedName(columnPath.getLastClassDescriptor() .getName()); Class typeCls = columnPath.getLastClassDescriptor().getType(); String columnDescription = pathQuery.getGeneratedPathDescription(columnPath. toStringNoConstraints()); Column column; if (columnDescription.equals(columnPath.toStringNoConstraints())) { column = new Column(columnPath, i, typeCls); } else { column = new Column(columnPath, columnDescription, i, typeCls); } if (!types.contains(column.getColumnId())) { String fieldName = columnPath.getEndFieldDescriptor().getName(); boolean isKeyField = ClassKeyHelper.isKeyField(classKeys, type, fieldName); if (isKeyField) { column.setSelectable(true); types.add(column.getColumnId()); } } columns.add(column); i++; } }
public void testShortPath() throws Exception { String stringPath = "Department"; Path path = new Path(model, stringPath); ClassDescriptor cld = model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Department"); assertEquals(cld, path.getStartClassDescriptor()); assertEquals(cld, path.getEndClassDescriptor()); assertNull(path.getEndFieldDescriptor()); //assertEquals(Department.class, path.getEndType()); }
public void testValid() throws Exception { String stringPath = "Department.company"; Path path = new Path(model, stringPath); ClassDescriptor cld = model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Department"); assertEquals(cld, path.getStartClassDescriptor()); FieldDescriptor fld = cld.getFieldDescriptorByName("company"); assertEquals(fld, path.getEndFieldDescriptor()); ClassDescriptor compDesc = model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Company"); assertEquals(compDesc, path.getEndClassDescriptor()); assertFalse(path.containsCollections()); assertEquals(stringPath, path.toString()); }