/** * Returns a representation of the Path as a String, with no class constraint markers. eg. * "Department.employees.seniority" * @return a String version of the Path */ public String toStringNoConstraints() { StringBuffer sb = new StringBuffer(); for (int i = 0; i < elements.size(); i++) { sb.append(outers.get(i).booleanValue() ? ":" : "."); sb.append(elements.get(i)); } return getStartClassDescriptor().getUnqualifiedName() + sb.toString(); }
/** * Returns a representation of the Path as a String, with no class constraint markers. eg. * "Department.employees.seniority" * @return a String version of the Path */ public String toStringNoConstraints() { StringBuffer sb = new StringBuffer(); for (int i = 0; i < elements.size(); i++) { sb.append(outers.get(i).booleanValue() ? ":" : "."); sb.append(elements.get(i)); } return getStartClassDescriptor().getUnqualifiedName() + sb.toString(); }
String cdUnqualifiedName = getStartClassDescriptor().getUnqualifiedName(); StringBuffer returnStringBuffer = new StringBuffer(cdUnqualifiedName);
String cdUnqualifiedName = getStartClassDescriptor().getUnqualifiedName(); StringBuffer returnStringBuffer = new StringBuffer(cdUnqualifiedName);
private Set<String> validateView(List<String> problems, Set<String> validMainPaths) { if (view.isEmpty()) { problems.add(NO_VIEW_ERROR); } else { for (String viewPath : view) { try { Path path = new Path(model, viewPath, subclasses); if (!path.endIsAttribute()) { problems.add("Path " + viewPath + " in view list must be an attribute"); continue; } if (rootClass == null) { rootClass = path.getStartClassDescriptor().getUnqualifiedName(); } else { String newRootClass = path.getStartClassDescriptor().getUnqualifiedName(); if (!rootClass.equals(newRootClass)) { problems.add("Multiple root classes in query: " + rootClass + " and " + newRootClass); continue; } } addValidPaths(validMainPaths, path.getPrefix()); } catch (PathException e) { problems.add("Path " + viewPath + " in view list is not in the model"); } } } return validMainPaths; }
private Set<String> validateView(List<String> problems, Set<String> validMainPaths) { if (view.isEmpty()) { problems.add(NO_VIEW_ERROR); } else { for (String viewPath : view) { try { Path path = new Path(model, viewPath, subclasses); if (!path.endIsAttribute()) { problems.add("Path " + viewPath + " in view list must be an attribute"); continue; } if (rootClass == null) { rootClass = path.getStartClassDescriptor().getUnqualifiedName(); } else { String newRootClass = path.getStartClassDescriptor().getUnqualifiedName(); if (!rootClass.equals(newRootClass)) { problems.add("Multiple root classes in query: " + rootClass + " and " + newRootClass); continue; } } addValidPaths(validMainPaths, path.getPrefix()); } catch (PathException e) { problems.add("Path " + viewPath + " in view list is not in the model"); } } } return validMainPaths; }
try { Path path = new Path(model, constraintEntry.getKey().getPath(), subclasses); if (path.getStartClassDescriptor().getUnqualifiedName().equals(rootClass)) { if (path.endIsAttribute()) { path = path.getPrefix();
try { Path path = new Path(model, constraintEntry.getKey().getPath(), subclasses); if (path.getStartClassDescriptor().getUnqualifiedName().equals(rootClass)) { if (path.endIsAttribute()) { path = path.getPrefix();
if (path.getStartClassDescriptor() != null) { Set<ClassDescriptor> clds = model.getClassDescriptorsForClass(o.getClass()); if (!clds.contains(path.getStartClassDescriptor())) { throw new PathException("ClassDescriptor from the start of path: " + path + " is not a superclass of the class: "
if (path.getStartClassDescriptor() != null) { Set<ClassDescriptor> clds = model.getClassDescriptorsForClass(o.getClass()); if (!clds.contains(path.getStartClassDescriptor())) { throw new PathException("ClassDescriptor from the start of path: " + path + " is not a superclass of the class: "
String rootOfStringPath = path.getStartClassDescriptor().getUnqualifiedName(); if ((lRootClass != null) && (!lRootClass.equals(rootOfStringPath))) { throw new NoSuchElementException("Path " + stringPath + " is not in the query");
String rootOfStringPath = path.getStartClassDescriptor().getUnqualifiedName(); if ((lRootClass != null) && (!lRootClass.equals(rootOfStringPath))) { throw new NoSuchElementException("Path " + stringPath + " is not in the query");
if (path.getStartClassDescriptor() != null) { Set<ClassDescriptor> clds = model.getClassDescriptorsForClass(o.getClass()); if (!clds.contains(path.getStartClassDescriptor())) { throw new PathException("ClassDescriptor from the start of path: " + path + " is not a superclass of the class: "
public void testValid3() throws Exception { String stringPath = "Employee.age"; Path path = new Path(model, stringPath); assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Employee"), path.getStartClassDescriptor()); assertEquals(Integer.class, path.getEndType()); }
public void testValid2() throws Exception { String stringPath = "Department.company.name"; Path path = new Path(model, stringPath); ClassDescriptor cld = model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Department"); assertEquals(String.class, path.getEndType()); assertEquals(cld, path.getStartClassDescriptor()); }
private void checkConstrainedPath(Path path) { assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Department"), path.getStartClassDescriptor()); assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Department"), path.getElementClassDescriptors().get(0)); assertEquals("manager", path.getElements().get(0)); assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.CEO"), path.getElementClassDescriptors().get(1)); assertEquals("company", path.getElements().get(1)); assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Company"), path.getElementClassDescriptors().get(2)); assertEquals("departments", path.getElements().get(2)); assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Department"), path.getElementClassDescriptors().get(3)); assertEquals("employees", path.getElements().get(3)); assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Manager"), path.getElementClassDescriptors().get(4)); assertEquals("age", path.getElements().get(4)); assertEquals(Integer.class, path.getEndType()); }
/** * 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; }
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()); }
/** * 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; }
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()); }