예제 #1
0
  /** {@inheritDoc} */
  public ActionForward execute(
      @SuppressWarnings("unused") ActionMapping mapping,
      @SuppressWarnings("unused") ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    String type = request.getParameter("type");
    if (type == null) {
      type = "webapp";
    }

    if ("webapp".equals(type)) {
      response.getOutputStream().print("OK");
    } else if ("query".equals(type)) {
      final InterMineAPI im = SessionMethods.getInterMineAPI(request.getSession());
      ObjectStore os = im.getObjectStore();
      Query q = new Query();
      QueryClass c = new QueryClass(InterMineObject.class);
      q.addFrom(c);
      q.addToSelect(c);
      // Add a unique value to the select to avoid caching the query
      QueryValue token = new QueryValue(System.currentTimeMillis());
      q.addToSelect(token);
      Results r = os.execute(q, 1, false, false, false);
      if (r.get(0) != null) {
        response.getOutputStream().print("OK");
      } else {
        response.getOutputStream().print("NO RESULTS");
      }
    }
    return null;
  }
 public void testTranslation() throws Exception {
   ObjectStore os2 =
       new ObjectStoreTranslatingImpl(
           Model.getInstanceByName("testmodel"),
           ObjectStoreFactory.getObjectStore("os.unittest"),
           new CompanyTranslator());
   Query q = new Query();
   QueryClass qc = new QueryClass(InterMineObject.class);
   q.addToSelect(qc);
   q.addFrom(qc);
   Results res = os2.execute(q);
   assertEquals(2, res.size());
   assertEquals("CompanyA", ((Bank) ((ResultsRow) res.get(0)).get(0)).getName());
   assertEquals("CompanyB", ((Bank) ((ResultsRow) res.get(1)).get(0)).getName());
 }
예제 #3
0
  /**
   * @param os object store
   * @return map of name to so term
   * @throws ObjectStoreException if something goes wrong
   */
  protected Map<String, SOTerm> populateSOTermMap(ObjectStore os) throws ObjectStoreException {
    Map<String, SOTerm> soTerms = new HashMap<String, SOTerm>();
    Query q = new Query();
    q.setDistinct(false);

    QueryClass qcSOTerm = new QueryClass(SOTerm.class);
    q.addToSelect(qcSOTerm);
    q.addFrom(qcSOTerm);
    q.addToOrderBy(qcSOTerm);

    Results res = os.execute(q);

    Iterator it = res.iterator();

    while (it.hasNext()) {
      ResultsRow<InterMineObject> rr = (ResultsRow<InterMineObject>) it.next();
      SOTerm soTerm = (SOTerm) rr.get(0);
      soTerms.put(soTerm.getName(), soTerm);
    }
    return soTerms;
  }
예제 #4
0
  public void testLoad() throws Exception {

    TSVFileReaderTask tsvTask = new TSVFileReaderTask();
    tsvTask.setIgnoreDuplicates(true);
    tsvTask.setIntegrationWriterAlias("integration.unittestmulti");
    tsvTask.setSourceName("testsource");

    cleanObjects(tsvTask.getDirectDataLoader().getIntegrationWriter());

    File tempFile = File.createTempFile("TSVFileReaderTaskTest", "tmp");
    FileWriter fw = new FileWriter(tempFile);
    InputStream is = getClass().getClassLoader().getResourceAsStream("TSVFileReaderTaskTest.tsv");
    BufferedReader br = new BufferedReader(new InputStreamReader(is));

    String line = null;
    while ((line = br.readLine()) != null) {
      fw.write(line + "\n");
    }

    fw.close();

    FileSet fileSet = new FileSet();

    fileSet.setFile(tempFile);

    tsvTask.addFileSet(fileSet);

    InputStream confInputStream =
        getClass().getClassLoader().getResourceAsStream("TSVFileReaderTaskTest.properties");
    DelimitedFileConfiguration dfc = new DelimitedFileConfiguration(model, confInputStream);

    tsvTask.executeInternal(dfc, tempFile);

    // Check the results to see if we have some data...
    ObjectStore os = tsvTask.getDirectDataLoader().getIntegrationWriter().getObjectStore();

    Query q = new Query();
    QueryClass empQueryClass = new QueryClass(Employee.class);
    QueryField qf0 = new QueryField(empQueryClass, "age");
    QueryField qf1 = new QueryField(empQueryClass, "name");
    QueryField qf2 = new QueryField(empQueryClass, "fullTime");

    q.addToSelect(qf0);
    q.addToSelect(qf1);
    q.addToSelect(qf2);
    q.addFrom(empQueryClass);

    q.addToOrderBy(qf1);

    Results r = os.execute(q);

    if (r.size() != 3) {
      for (List<Object> rr : (List<List<Object>>) ((List) r)) {
        System.err.print("row: ");
        for (Object obj : rr) {
          System.err.print("{" + obj + "} ");
        }
        System.err.println();
      }
    }

    assertEquals(3, r.size());

    List expectedRow0 = Arrays.asList(new Object[] {new Integer(10), "EmployeeA1", Boolean.FALSE});
    assertEquals(expectedRow0, r.get(0));

    List expectedRow1 = Arrays.asList(new Object[] {new Integer(20), "EmployeeA2", Boolean.TRUE});
    assertEquals(expectedRow1, r.get(1));

    List expectedRow2 = Arrays.asList(new Object[] {new Integer(0), "EmployeeA3", Boolean.FALSE});
    assertEquals(expectedRow2, r.get(2));
  }
예제 #5
0
  /**
   * Read the UTRs collection of MRNA then set the fivePrimeUTR and threePrimeUTR fields with the
   * corresponding UTRs.
   *
   * @throws Exception if anything goes wrong
   */
  public void createUtrRefs() throws Exception {
    long startTime = System.currentTimeMillis();
    Query q = new Query();
    q.setDistinct(false);

    QueryClass qcMRNA = new QueryClass(model.getClassDescriptorByName("MRNA").getType());
    q.addFrom(qcMRNA);
    q.addToSelect(qcMRNA);
    q.addToOrderBy(qcMRNA);

    QueryClass qcUTR = new QueryClass(model.getClassDescriptorByName("UTR").getType());
    q.addFrom(qcUTR);
    q.addToSelect(qcUTR);
    q.addToOrderBy(qcUTR);

    QueryCollectionReference mrnaUtrsRef = new QueryCollectionReference(qcMRNA, "UTRs");
    ContainsConstraint mrnaUtrsConstraint =
        new ContainsConstraint(mrnaUtrsRef, ConstraintOp.CONTAINS, qcUTR);

    QueryObjectReference fivePrimeRef = new QueryObjectReference(qcMRNA, "fivePrimeUTR");
    ContainsConstraint fivePrimeNullConstraint =
        new ContainsConstraint(fivePrimeRef, ConstraintOp.IS_NULL);
    QueryObjectReference threePrimeRef = new QueryObjectReference(qcMRNA, "threePrimeUTR");
    ContainsConstraint threePrimeNullConstraint =
        new ContainsConstraint(threePrimeRef, ConstraintOp.IS_NULL);

    ConstraintSet cs = new ConstraintSet(ConstraintOp.AND);
    cs.addConstraint(mrnaUtrsConstraint);
    cs.addConstraint(fivePrimeNullConstraint);
    cs.addConstraint(threePrimeNullConstraint);

    q.setConstraint(cs);

    ObjectStore os = osw.getObjectStore();

    ((ObjectStoreInterMineImpl) os).precompute(q, Constants.PRECOMPUTE_CATEGORY);
    Results res = os.execute(q, 500, true, true, true);

    int count = 0;
    InterMineObject lastMRNA = null;

    InterMineObject fivePrimeUTR = null;
    InterMineObject threePrimeUTR = null;

    osw.beginTransaction();

    Class<? extends FastPathObject> fivePrimeUTRCls =
        model.getClassDescriptorByName("FivePrimeUTR").getType();

    Iterator<?> resIter = res.iterator();
    while (resIter.hasNext()) {
      ResultsRow<?> rr = (ResultsRow<?>) resIter.next();
      InterMineObject mrna = (InterMineObject) rr.get(0);
      InterMineObject utr = (InterMineObject) rr.get(1);

      if (lastMRNA != null && !mrna.getId().equals(lastMRNA.getId())) {
        // clone so we don't change the ObjectStore cache
        InterMineObject tempMRNA = PostProcessUtil.cloneInterMineObject(lastMRNA);
        if (fivePrimeUTR != null) {
          tempMRNA.setFieldValue("fivePrimeUTR", fivePrimeUTR);
          fivePrimeUTR = null;
        }
        if (threePrimeUTR != null) {
          tempMRNA.setFieldValue("threePrimeUTR", threePrimeUTR);
          threePrimeUTR = null;
        }
        osw.store(tempMRNA);
        count++;
      }

      if (DynamicUtil.isInstance(utr, fivePrimeUTRCls)) {
        fivePrimeUTR = utr;
      } else {
        threePrimeUTR = utr;
      }

      lastMRNA = mrna;
    }

    if (lastMRNA != null) {
      // clone so we don't change the ObjectStore cache
      InterMineObject tempMRNA = PostProcessUtil.cloneInterMineObject(lastMRNA);
      tempMRNA.setFieldValue("fivePrimeUTR", fivePrimeUTR);
      tempMRNA.setFieldValue("threePrimeUTR", threePrimeUTR);
      osw.store(tempMRNA);
      count++;
    }
    LOG.info(
        "Stored MRNA "
            + count
            + " times ("
            + count * 2
            + " fields set)"
            + " - took "
            + (System.currentTimeMillis() - startTime)
            + " ms.");
    osw.commitTransaction();

    // now ANALYSE tables relating to class that has been altered - may be rows added
    // to indirection tables
    if (osw instanceof ObjectStoreWriterInterMineImpl) {
      ClassDescriptor cld = model.getClassDescriptorByName("MRNA");
      DatabaseUtil.analyse(((ObjectStoreWriterInterMineImpl) osw).getDatabase(), cld, false);
    }
  }