Пример #1
0
 /**
  * Generates the getElementType method.
  *
  * @param cld the ClassDescriptor
  * @return a String with the method
  */
 public String generateGetElementType(ClassDescriptor cld) {
   StringBuffer sb = new StringBuffer();
   sb.append(INDENT).append("public Class<?> getElementType(final String fieldName) {\n");
   for (FieldDescriptor field : cld.getAllFieldDescriptors()) {
     if (field.isCollection()) {
       sb.append(INDENT + INDENT)
           .append("if (\"" + field.getName() + "\".equals(fieldName)) {\n")
           .append(INDENT + INDENT + INDENT)
           .append(
               "return " + ((CollectionDescriptor) field).getReferencedClassName() + ".class;\n")
           .append(INDENT + INDENT)
           .append("}\n");
     }
   }
   sb.append(INDENT + INDENT)
       .append("if (!" + cld.getName() + ".class.equals(getClass())) {\n")
       .append(INDENT + INDENT + INDENT)
       .append("return TypeUtil.getElementType(" + cld.getName() + ".class, fieldName);\n")
       .append(INDENT + INDENT)
       .append("}\n")
       .append(INDENT + INDENT)
       .append("throw new IllegalArgumentException(\"Unknown field \" + fieldName);\n")
       .append(INDENT)
       .append("}\n");
   return sb.toString();
 }
Пример #2
0
 private String getTaggedType(FieldDescriptor fd) {
   if (fd.isCollection()) {
     return "collection";
   } else if (fd.isReference()) {
     return "reference";
   }
   return "attribute";
 }
Пример #3
0
 /**
  * Generates the addCollectionElement method.
  *
  * @param cld the ClassDescriptor
  * @return a String with the method
  */
 public String generateAddCollectionElement(ClassDescriptor cld) {
   StringBuffer sb = new StringBuffer();
   sb.append(INDENT)
       .append("public void addCollectionElement(final String fieldName,")
       .append(" final org.intermine.model.InterMineObject element) {\n")
       .append(INDENT + INDENT);
   for (FieldDescriptor field : cld.getAllFieldDescriptors()) {
     if (field.isCollection()) {
       String fieldName = field.getName();
       if ("fieldName".equals(fieldName)) {
         fieldName = "this.fieldName";
       } else if ("element".equals(fieldName)) {
         fieldName = "this.element";
       }
       sb.append("if (\"" + field.getName() + "\".equals(fieldName)) {\n")
           .append(INDENT + INDENT + INDENT)
           .append(
               fieldName
                   + ".add(("
                   + ((CollectionDescriptor) field).getReferencedClassName()
                   + ") element);\n")
           .append(INDENT + INDENT)
           .append("} else ");
     }
   }
   sb.append("{\n")
       .append(INDENT + INDENT + INDENT)
       .append("if (!" + cld.getName() + ".class.equals(getClass())) {\n")
       .append(INDENT + INDENT + INDENT + INDENT)
       .append("TypeUtil.addCollectionElement(this, fieldName, element);\n")
       .append(INDENT + INDENT + INDENT + INDENT)
       .append("return;\n")
       .append(INDENT + INDENT + INDENT)
       .append("}\n")
       .append(INDENT + INDENT + INDENT)
       .append("throw new IllegalArgumentException(\"Unknown collection \" + fieldName);\n")
       .append(INDENT + INDENT)
       .append("}\n")
       .append(INDENT)
       .append("}\n");
   return sb.toString();
 }
  @Override
  public void display(HttpServletRequest request, ReportObject reportObject) {

    // get the gene/protein in question from the request
    InterMineObject object = reportObject.getObject();

    // API connection
    HttpSession session = request.getSession();
    final InterMineAPI im = SessionMethods.getInterMineAPI(session);
    Model model = im.getModel();
    PathQuery query = new PathQuery(model);

    // cast me Gene
    Gene gene = (Gene) object;
    Object genePrimaryIDObj = gene.getPrimaryIdentifier();
    if (genePrimaryIDObj != null) {
      // fetch the expression
      String genePrimaryID = String.valueOf(genePrimaryIDObj);
      query = geneExpressionAtlasQuery(genePrimaryID, query);

      // execute the query
      Profile profile = SessionMethods.getProfile(session);
      PathQueryExecutor executor = im.getPathQueryExecutor(profile);
      ExportResultsIterator values = executor.execute(query);

      // convert to a map
      GeneExpressionAtlasDiseasesExpressions geae =
          new GeneExpressionAtlasDiseasesExpressions(values);

      // attach to results
      request.setAttribute("expressions", geae);
      request.setAttribute("url", "http://www.ebi.ac.uk/gxa/experiment/E-MTAB-62/" + genePrimaryID);
      request.setAttribute("defaultPValue", "1e-4");
      request.setAttribute("defaultTValue", "4");

      // get the corresponding collection
      for (FieldDescriptor fd : reportObject.getClassDescriptor().getAllFieldDescriptors()) {
        if ("atlasExpression".equals(fd.getName()) && fd.isCollection()) {
          // fetch the collection
          Collection<?> collection = null;
          try {
            collection = (Collection<?>) reportObject.getObject().getFieldValue("atlasExpression");
          } catch (IllegalAccessException e) {
            e.printStackTrace();
          }

          List<Class<?>> lc =
              PathQueryResultHelper.queryForTypesInCollection(
                  reportObject.getObject(), "atlasExpression", im.getObjectStore());

          // create an InlineResultsTable
          InlineResultsTable t =
              new InlineResultsTable(
                  collection,
                  fd.getClassDescriptor().getModel(),
                  SessionMethods.getWebConfig(request),
                  im.getClassKeys(),
                  collection.size(),
                  false,
                  lc);

          request.setAttribute("collection", t);
          break;
        }
      }
    }
  }