/**
  * transfers with detachment ResultElement's in one ResultsElement to another.
  *
  * @param subResultsElement source of ResultElement's
  */
 public void transferResultElements(ResultsElement subResultsElement) {
   //		List<ResultElement> subResults = subResultsElement.getOrCreateResultElementList();
   for (ResultElement subResult : subResultsElement) {
     subResult.detach();
     this.appendChild(subResult);
   }
 }
 public List<String> getExactList() {
   if (matchList == null) {
     matchList = new ArrayList<String>();
     for (ResultElement resultElement : this) {
       String name = resultElement.getExact();
       matchList.add(name);
     }
   }
   return matchList;
 }
 public void addMatchAttributes(List<String> matchList) {
   if (this.size() != matchList.size()) {
     throw new RuntimeException(
         "name list wrong length (" + matchList.size() + ") rather than (" + this.size() + ")");
   }
   int i = 0;
   for (ResultElement resultElement : this) {
     resultElement.setMatch(matchList.get(i));
     // cosmetic - keeps attributes in natural order
     resultElement.setPost(resultElement.getPost());
     i++;
   }
 }
 public void lookup(Map<String, AbstractLookup> lookupInstanceByName, List<String> lookupNames) {
   if (lookupInstanceByName != null && lookupNames != null) {
     for (String lookupName : lookupNames) {
       AbstractLookup abstractLookup = lookupInstanceByName.get(lookupName);
       for (ResultElement element : resultElementList) {
         String exact = element.getExact();
         try {
           String lookupId = abstractLookup.lookup(exact);
           element.setId(lookupName, lookupId);
         } catch (IOException e) {
           LOG.debug("lookup failed", e);
         }
       }
     }
   }
 }
 public void setXPath(String xpath) {
   for (ResultElement resultElement : this) {
     resultElement.setXPath(xpath);
   }
 }
 public void setAllResultElementNames(String name) {
   for (ResultElement resultElement : this) {
     resultElement.setName(name);
   }
 }
Example #7
0
  // TODO javadoc to describe what this does
  private MultiRow<ResultsRow<MultiRowValue<ResultElement>>> translateRow(
      MultiRow<ResultsRow<MultiRowValue>> multiRow) {
    try {
      MultiRow<ResultsRow<MultiRowValue<ResultElement>>> retval =
          new MultiRow<ResultsRow<MultiRowValue<ResultElement>>>();
      for (ResultsRow<MultiRowValue> initialList : multiRow) {
        ResultsRow<MultiRowValue<ResultElement>> rowCells =
            new ResultsRow<MultiRowValue<ResultElement>>();
        for (Path columnPath : columnPaths) {
          String columnName = columnPath.toStringNoConstraints();
          Integer columnIndexInteger = pathToIndex.get(columnName);
          String parentColumnName = columnPath.getPrefix().toStringNoConstraints();
          if (columnIndexInteger == null) {
            columnIndexInteger = pathToIndex.get(parentColumnName);
          }

          if (columnIndexInteger == null) {
            throw new NullPointerException(
                "Path: \""
                    + columnName
                    + "\", pathToIndex: \""
                    + pathToIndex
                    + "\", prefix: \""
                    + parentColumnName
                    + "\", query: \""
                    + PathQueryBinding.marshal(
                        pathQuery,
                        "",
                        pathQuery.getModel().getName(),
                        PathQuery.USERPROFILE_VERSION)
                    + "\"");
          }
          int columnIndex = columnIndexInteger.intValue();
          MultiRowValue origO = initialList.get(columnIndex);
          FastPathObject o = (FastPathObject) (origO == null ? null : origO.getValue());
          int rowspan = -1;
          if (origO == null) {
            rowspan = 1;
          } else if (origO instanceof MultiRowFirstValue) {
            rowspan = ((MultiRowFirstValue) origO).getRowspan();
          }
          String lastCd;
          if (columnPath.endIsAttribute()) {
            lastCd = columnPath.getLastClassDescriptor().getName();
          } else {
            // special case for columns that contain objects eg. Gene.chromosomeLocation
            lastCd = columnPath.getLastClassDescriptor().getName();
          }
          String type = TypeUtil.unqualifiedName(lastCd);
          Path path;
          String fieldName = null;
          try {
            if (columnPath.endIsAttribute()) {
              fieldName = columnName.substring(columnName.lastIndexOf(".") + 1);
              path = new Path(model, type + '.' + fieldName);
            } else {
              // special case for columns that contain objects
              path = new Path(model, type);
            }
          } catch (PathException e) {
            // Should never happen if the field name is valid
            throw new Error("There must be a bug", e);
          }

          // Three cases:
          // 1) attribute has a value so create a result element
          // 2) we have an object but attribute is null -> create a ResultElement with
          // value null
          // 3) the object is null (outer join) so add null value rowCells
          //                    Object fieldValue;
          //                    try {
          //                        fieldValue = (o == null ? null : PathUtil.resolvePath(path, o));
          //                    } catch (PathException e) {
          //                        throw new IllegalArgumentException("Path: \"" + columnName
          //                                + "\", pathToIndex: \"" + pathToIndex + "\", prefix: \""
          //                                + parentColumnName + "\", query: \""
          //                                + PathQueryBinding.marshal(pathQuery, "",
          // pathQuery.getModel()
          //                                    .getName(), PathQuery.USERPROFILE_VERSION)
          //                                + "\", columnIndex: \"" + columnIndex + "\",
          // initialList: \""
          //                                + initialList + "\"", e);
          //                    }
          if (o != null) {
            String fieldCDName = path.getLastClassDescriptor().getName();
            String unqualifiedFieldCD = TypeUtil.unqualifiedName(fieldCDName);
            boolean isKeyField;
            if (fieldName == null) {
              // special case for columns that contain objects
              isKeyField = false;
            } else {
              isKeyField = ClassKeyHelper.isKeyField(classKeys, unqualifiedFieldCD, fieldName);
            }
            ResultElement resultElement = new ResultElement(o, path, isKeyField);
            // link to report page by default, unless it says otherwise in config

            if (redirector != null) {
              try {
                String linkRedirect = redirector.generateLink(im, (InterMineObject) o);
                if (linkRedirect != null) {
                  resultElement.setLinkRedirect(linkRedirect);
                }
              } catch (ClassCastException e) {
                // Simple objects cannot be consumed by redirectors.
              }
            }

            if (rowspan >= 0) {
              rowCells.add(new MultiRowFirstValue(resultElement, rowspan));
            } else {
              rowCells.add(null);
            }
          } else {
            if (rowspan >= 0) {
              rowCells.add(new MultiRowFirstValue(null, rowspan));
            } else {
              rowCells.add(null);
            }
          }
        }
        retval.add(rowCells);
      }
      return retval;
    } catch (IndexOutOfBoundsException e) {
      throw new RuntimeException(e);
    }
  }