コード例 #1
0
ファイル: WebResults.java プロジェクト: elcovi/modmine
  private void addColumnsInternal(List<Path> columnPaths) {
    List<String> types = new ArrayList<String>();
    int i = columns.size();
    for (Path columnPath : columnPaths) {
      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++;
    }
  }
コード例 #2
0
 private static Map<String, List<FieldDescriptor>> getClassKeys(ObjectStore os) {
   Properties classKeyProps = new Properties();
   try {
     InputStream inputStream =
         ProfileManagerBinding.class.getClassLoader().getResourceAsStream("class_keys.properties");
     classKeyProps.load(inputStream);
   } catch (IOException ioe) {
     throw new BuildException("class_keys.properties not found", ioe);
   }
   return ClassKeyHelper.readKeys(os.getModel(), classKeyProps);
 }
コード例 #3
0
  @Override
  public void execute() {
    System.out.println("Creating lucene index for keyword search...");

    ObjectStore os;
    try {
      os = getObjectStore();
    } catch (Exception e) {
      throw new BuildException(e);
    }
    if (!(os instanceof ObjectStoreInterMineImpl)) {
      // Yes, yes, this is horrific...
      throw new RuntimeException(
          "Got invalid ObjectStore - must be an " + "instance of ObjectStoreInterMineImpl!");
    }

    /*
    String configFileName = "objectstoresummary.config.properties";
    InputStream configStream = classLoader.getResourceAsStream(configFileName);
    if (configStream == null) {
        throw new RuntimeException("can't find resource: " + configFileName);
    }

    Properties properties = new Properties();
    properties.load(configStream);*/

    // read class keys to figure out what are keyFields during indexing
    InputStream is = this.getClass().getClassLoader().getResourceAsStream("class_keys.properties");
    Properties classKeyProperties = new Properties();
    try {
      classKeyProperties.load(is);
    } catch (NullPointerException e) {
      throw new BuildException("Could not find the class keys");
    } catch (IOException e) {
      throw new BuildException("Could not read the class keys", e);
    }
    Map<String, List<FieldDescriptor>> classKeys =
        ClassKeyHelper.readKeys(os.getModel(), classKeyProperties);

    // index and save
    KeywordSearch.saveIndexToDatabase(os, classKeys);
    KeywordSearch.deleteIndexDirectory();
  }
コード例 #4
0
ファイル: WebResults.java プロジェクト: elcovi/modmine
  // 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);
    }
  }