Ejemplo n.º 1
0
  private void addNewAdminRolesToRealm(BasicDBObject currentRealm) {
    DBCollection applications = db.getCollection("applications");
    DBCollection roles = db.getCollection("roles");

    BasicDBObject adminApp =
        (BasicDBObject)
            applications.findOne(
                new BasicDBObject()
                    .append("realmId", currentRealm.get("_id"))
                    .append("name", "realm-management"));

    String viewIdProvidersRoleId =
        insertApplicationRole(roles, AdminRoles.VIEW_IDENTITY_PROVIDERS, adminApp.getString("_id"));
    String manageIdProvidersRoleId =
        insertApplicationRole(
            roles, AdminRoles.MANAGE_IDENTITY_PROVIDERS, adminApp.getString("_id"));

    BasicDBObject adminRole =
        (BasicDBObject)
            roles.findOne(
                new BasicDBObject()
                    .append("applicationId", adminApp.get("_id"))
                    .append("name", AdminRoles.REALM_ADMIN));
    BasicDBList adminCompositeRoles = (BasicDBList) adminRole.get("compositeRoleIds");
    adminCompositeRoles.add(viewIdProvidersRoleId);
    adminCompositeRoles.add(manageIdProvidersRoleId);

    roles.save(adminRole);
    log.debugv(
        "Added roles {0} and {1} to application realm-management of realm {2}",
        AdminRoles.VIEW_IDENTITY_PROVIDERS,
        AdminRoles.MANAGE_IDENTITY_PROVIDERS,
        currentRealm.get("name"));
  }
Ejemplo n.º 2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * com.sg.ui.model.input.BusinessObjectRelationListInput#doQuery(com.mongodb
   * .DBObject)
   */
  @Override
  protected List<DBObject> doQuery(DBObject returnFields) {
    if (service == null) {
      service = getService();
    }
    DBObject projection = returnFields == null ? service.getDefaultSearchColumns() : returnFields;

    try {
      BasicDBList list = new BasicDBList();
      list.add(new BasicDBObject().append(Action.FIELD_OPPORTUNIY_ID, opportunityId));
      list.add(new BasicDBObject().append(Action.FIELD_OPPORTUNIY_ID, null));

      BasicDBObject query =
          new BasicDBObject().append(Action.FIELD_COMPANY_ID, companyId).append(Action.OR, list);

      DBCursor cursor = service.find(query, projection);
      DBObject sort = getSort();
      cursor.sort(sort);
      return cursor.toArray();

    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
Ejemplo n.º 3
0
  @Test
  public void testEquals3() throws Exception {
    System.out.println("testEquals3()");

    BasicDBList expectedlist = new BasicDBList();
    expectedlist.add("tool");
    expectedlist.add("stuff");
    BasicDBObject expected =
        new BasicDBObject()
            .append("stuff", true)
            .append("stuff1", 1234.0)
            .append("stuff0", expectedlist);

    BasicDBList actuallist = new BasicDBList();
    actuallist.add("tool");
    actuallist.add("stuff");
    BasicDBObject actual =
        new BasicDBObject()
            .append("stuff", true)
            .append("stuff1", 1234.0)
            .append("stuff0", actuallist);

    Assert.assertEquals(expected, actual);
    Assert.assertTrue(expected.equals(actual));
  }
Ejemplo n.º 4
0
  @Override
  public DBObject toJSON() {
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();

    BasicDBList jsonList = new BasicDBList();

    Iterator<VoronoiSite> sitesIt = this.sites.iterator();
    while (sitesIt.hasNext()) {
      jsonList.add(sitesIt.next().toJSON());
    }
    builder.add("sites", jsonList);

    jsonList = new BasicDBList();
    Iterator<VoronoiCorner> cornersIt = this.corners.iterator();
    while (cornersIt.hasNext()) {
      jsonList.add(cornersIt.next().toJSON());
    }
    builder.add("corners", jsonList);

    jsonList = new BasicDBList();
    Iterator<VoronoiEdge> edgesIt = this.edges.iterator();
    while (edgesIt.hasNext()) {
      jsonList.add(edgesIt.next().toJSON());
    }
    builder.add("edges", jsonList);

    return builder.get();
  }
Ejemplo n.º 5
0
  /** {@inheritDoc} */
  @Override
  public DBObject toDBObject(Music music) {
    DBObject doc = new BasicDBObject();

    doc.put("trackNumber", music.getTrackNumber());
    doc.put("title", music.getTitle());
    doc.put("artistName", music.getArtistName());
    doc.put("albumName", music.getAlbumName());

    if (music.getFileId() != null) {
      doc.put("fileId", new ObjectId(music.getFileId()));
    }

    BasicDBList tagsList = new BasicDBList();
    for (String tag : music.getTags()) {
      tagsList.add(tag);
    }
    doc.put("tags", tagsList);

    BasicDBList comentariosList = new BasicDBList();
    for (Comment comentario : music.getComments()) {
      comentariosList.add(commentConv.toDBObject(comentario));
    }
    doc.put("comments", comentariosList);

    return doc;
  }
Ejemplo n.º 6
0
  @Override
  public void update(KeycloakSession session) {
    BasicDBList orArgs = new BasicDBList();
    orArgs.add(new BasicDBObject("type", UserCredentialModel.PASSWORD));
    orArgs.add(new BasicDBObject("type", UserCredentialModel.PASSWORD_HISTORY));

    BasicDBObject elemMatch = new BasicDBObject("$or", orArgs);
    elemMatch.put("algorithm", new BasicDBObject("$exists", false));

    BasicDBObject query =
        new BasicDBObject("credentials", new BasicDBObject("$elemMatch", elemMatch));

    BasicDBObject update =
        new BasicDBObject(
            "$set", new BasicDBObject("credentials.$.algorithm", Pbkdf2PasswordHashProvider.ID));

    DBCollection users = db.getCollection("users");

    // Not sure how to do in single query
    int countModified = 1;
    while (countModified > 0) {
      WriteResult wr = users.update(query, update, false, true);
      countModified = wr.getN();
      log.debugf(
          "%d credentials modified in current iteration during upgrade to 1.8", countModified);
    }
  }
Ejemplo n.º 7
0
  public void run() throws UnknownHostException {
    final List<Integer> models = new ArrayList<Integer>();
    final List<String> owners = new ArrayList<String>();
    final MongoClient client = new MongoClient();

    DB db = client.getDB("mongo_hadoop");
    DBCollection devices = db.getCollection("devices");
    DBCollection logs = db.getCollection("logs");

    if ("true".equals(System.getenv("SENSOR_DROP"))) {
      LOG.info("Dropping sensor data");
      devices.drop();
      logs.drop();
      devices.createIndex(new BasicDBObject("devices", 1));
    }
    db.getCollection("logs_aggregate").createIndex(new BasicDBObject("devices", 1));

    if (logs.count() == 0) {
      for (int i = 0; i < 10; i++) {
        owners.add(getRandomString(10));
      }

      for (int i = 0; i < 10; i++) {
        models.add(getRandomInt(10, 20));
      }

      List<ObjectId> deviceIds = new ArrayList<ObjectId>();
      for (int i = 0; i < NUM_DEVICES; i++) {
        DBObject device =
            new BasicDBObject("_id", new ObjectId())
                .append("name", getRandomString(5) + getRandomInt(3, 5))
                .append("type", choose(TYPES))
                .append("owner", choose(owners))
                .append("model", choose(models))
                .append("created_at", randomDate(new Date(2000, 1, 1, 16, 49, 29), new Date()));
        deviceIds.add((ObjectId) device.get("_id"));
        devices.insert(device);
      }

      for (int i = 0; i < NUM_LOGS; i++) {
        if (i % 50000 == 0) {
          LOG.info(format("Creating %d sensor log data entries: %d%n", NUM_LOGS, i));
        }
        BasicDBList location = new BasicDBList();
        location.add(getRandomInRange(-180, 180, 3));
        location.add(getRandomInRange(-90, 90, 3));
        DBObject log =
            new BasicDBObject("_id", new ObjectId())
                .append("d_id", choose(deviceIds))
                .append("v", getRandomInt(0, 10000))
                .append("timestamp", randomDate(new Date(2013, 1, 1, 16, 49, 29), new Date()))
                .append("loc", location);
        logs.insert(log);
      }
    }
  }
Ejemplo n.º 8
0
  @Test
  public void bench2() throws Exception {
    System.out.println("bench2()");

    int TEST_TO = 100000;

    BasicDBList expectedlist = new BasicDBList();
    expectedlist.add(new BasicDBObject().append("first1", 1234.0).append("first2", "hello"));
    expectedlist.add(new BasicDBObject().append("first1", 2345.0).append("first2", "hello2"));
    BasicDBObject expected =
        new BasicDBObject().append("stuff", true).append("stuff4", expectedlist);
    doBench(TEST_TO, expected);
  }
Ejemplo n.º 9
0
 public static BasicDBList encodeArray(JsonArray a) {
   BasicDBList dbl = new BasicDBList();
   for (JsonElement el : a) {
     dbl.add(encodeUnknown(el));
   }
   return dbl;
 } // TESTED
  @Override
  public void insertModel(Server model) {
    BasicDBObject dbServer = new BasicDBObject();
    dbServer.put("_id", model.getId());
    dbServer.put("created_at", model.getCreated_at());
    dbServer.put("updated_at", model.getUpdated_at());
    dbServer.put("network_id", model.getNetwork().getId().toString());
    dbServer.put("node_id", null);
    dbServer.put("server_type_id", model.getServerType().getId().toString());
    dbServer.put("port", 0);
    dbServer.put("container", "NULL");
    dbServer.put("players", new BasicDBObject());

    BasicDBList metaDataList = new BasicDBList();
    for (Map.Entry<String, ServerMetaData> metaDataEntry : model.getMetaData().entrySet()) {
      DBObject dbMetaData = new BasicDBObject();
      dbMetaData.put("_id", metaDataEntry.getValue().getId());
      dbMetaData.put("created_at", metaDataEntry.getValue().getCreated_at());
      dbMetaData.put("updated_at", metaDataEntry.getValue().getUpdated_at());
      dbMetaData.put("key", metaDataEntry.getValue().getKey());
      dbMetaData.put("value", metaDataEntry.getValue().getValue());
      metaDataList.add(dbMetaData);
    }
    dbServer.put("metaData", metaDataList);

    dbServer.put("number", 0);

    getDatabase().insert("servers", dbServer);
  }
  @Override
  public void saveModel(Server model) {
    BasicDBObject dbServer = new BasicDBObject();
    dbServer.put("updated_at", model.getUpdated_at());
    if (model.getNode() != null) {
      dbServer.put("node_id", model.getNode().getId().toString());
    }
    dbServer.put("port", model.getPort());
    dbServer.put("container", model.getContainerId());
    dbServer.put("players", new BasicDBObject(model.getPlayers()));

    BasicDBList metaDataList = new BasicDBList();
    for (Map.Entry<String, ServerMetaData> metaDataEntry : model.getMetaData().entrySet()) {
      DBObject dbMetaData = new BasicDBObject();
      dbMetaData.put("_id", metaDataEntry.getValue().getId());
      dbMetaData.put("created_at", metaDataEntry.getValue().getCreated_at());
      dbMetaData.put("updated_at", metaDataEntry.getValue().getUpdated_at());
      dbMetaData.put("key", metaDataEntry.getValue().getKey());
      dbMetaData.put("value", metaDataEntry.getValue().getValue());
      metaDataList.add(dbMetaData);
    }

    dbServer.put("metaData", metaDataList);

    dbServer.put("number", model.getNumber());
    getDatabase()
        .updateDocument(
            "servers",
            new BasicDBObject("_id", model.getId()),
            new BasicDBObject("$set", dbServer));
  }
  @Override
  public QueryResponse getAllByPositionList(List<Position> positionList, QueryOptions options) {
    //  db.regulatory_region.find({"chunkIds": {$in:["1_200", "1_300"]}, "start": 601156})

    String featureType = options.getString("featureType", null);
    String featureClass = options.getString("featureClass", null);

    List<DBObject> queries = new ArrayList<>();
    for (Position position : positionList) {
      String chunkId =
          position.getChromosome() + "_" + getChunkId(position.getPosition(), CHUNKSIZE);
      BasicDBList chunksId = new BasicDBList();
      chunksId.add(chunkId);
      QueryBuilder builder =
          QueryBuilder.start("chunkIds").in(chunksId).and("start").is(position.getPosition());
      if (featureType != null) {
        builder.and("featureType").is(featureType);
      }
      if (featureClass != null) {
        builder.and("featureClass").is(featureClass);
      }

      //        System.out.println("Query: " + builder.get());
      queries.add(builder.get());
    }

    System.out.println("Query: " + queries);

    options = addExcludeReturnFields("chunkIds", options);
    return executeQueryList(positionList, queries, options);
  }
Ejemplo n.º 13
0
 private DBObject marshallCollection(Collection<?> parameters) {
   BasicDBList list = new BasicDBList();
   for (Object param : parameters) {
     list.add(marshallParameter(param));
   }
   return list;
 }
Ejemplo n.º 14
0
  private String selectBooks(
      String schema, String collection, String title, String author, String isbn)
      throws UnknownHostException {
    System.out.println(schema);
    System.out.println(collection);
    System.out.println(title);
    System.out.println(author);
    List<String> l = new ArrayList<String>();
    MongoDBConnectionManager mgr = MongoDBConnectionManager.getInstance();
    Mongo mongo = mgr.getMongo();
    DB db = mongo.getDB(schema);

    try {
      DBCollection c = db.getCollection(collection);
      BasicDBObject titleQuery = new BasicDBObject();
      titleQuery.put("title", new BasicDBObject("$regex", title));
      BasicDBObject authorQuery = new BasicDBObject();
      authorQuery.put("author", new BasicDBObject("$regex", author));

      BasicDBList or = new BasicDBList();
      or.add(titleQuery);
      or.add(titleQuery);

      DBObject query = new BasicDBObject("$and", or);

      DBCursor cursor = c.find(titleQuery);
      while (cursor.hasNext()) l.add(cursor.next().toString());
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    System.out.println(l);
    if (l.size() > 0) return l.toString();
    else return null;
  }
Ejemplo n.º 15
0
 protected BasicDBList list(Object... values) {
   BasicDBList list = new BasicDBList();
   for (Object v : values) {
     list.add(v);
   }
   return list;
 }
Ejemplo n.º 16
0
 private DBObject marshallArray(Object[] parameters) {
   BasicDBList list = new BasicDBList();
   for (int i = 0; i < parameters.length; i++) {
     list.add(marshallParameter(parameters[i]));
   }
   return list;
 }
Ejemplo n.º 17
0
  @Test
  public void testGetStreamRules() {
    BasicDBObject mongoList = this.buildMongoBlacklist();

    BasicDBObject mongoRule1 = new BasicDBObject();
    mongoRule1.put("_id", new ObjectId());
    mongoRule1.put("blacklist_id", mongoList.get("_id"));
    mongoRule1.put("term", "^foo.+");

    BasicDBObject mongoRule2 = new BasicDBObject();
    mongoRule2.put("_id", new ObjectId());
    mongoRule1.put("blacklist_id", mongoList.get("_id"));
    mongoRule2.put("term", ".+bar");

    BasicDBList rules = new BasicDBList();
    rules.add(mongoRule1);
    rules.add(mongoRule2);

    mongoList.put("blacklisted_terms", rules);

    Blacklist blacklist = new Blacklist(mongoList);

    assertEquals(2, blacklist.getRules().size());
    assertEquals("^foo.+", blacklist.getRules().get(0).getTerm());
    assertEquals(".+bar", blacklist.getRules().get(1).getTerm());
  }
Ejemplo n.º 18
0
  @Test
  public void testBlacklistedWithPositiveResultAndNewline() {
    BasicDBObject mongoList = new BasicDBObject();
    mongoList.put("_id", new ObjectId());
    mongoList.put("title", "foo");

    BasicDBObject mongoRule1 = new BasicDBObject();
    mongoRule1.put("_id", new ObjectId());
    mongoRule1.put("blacklist_id", mongoList.get("_id"));
    mongoRule1.put("term", "^ohai.+");

    BasicDBObject mongoRule2 = new BasicDBObject();
    mongoRule2.put("_id", new ObjectId());
    mongoRule1.put("blacklist_id", mongoList.get("_id"));
    mongoRule2.put("term", ".+aarrghhhllll");

    BasicDBList rules = new BasicDBList();
    rules.add(mongoRule1);
    rules.add(mongoRule2);

    mongoList.put("blacklisted_terms", rules);

    Blacklist blacklist = new Blacklist(mongoList);

    GELFMessage msg = new GELFMessage();
    msg.setShortMessage("ohai thar\nfoo");

    List<Blacklist> blacklists = new ArrayList<Blacklist>();
    blacklists.add(blacklist);

    assertTrue(msg.blacklisted(blacklists));
  }
Ejemplo n.º 19
0
  @Test
  public void testEquals6() throws Exception {
    System.out.println("testEquals6()");

    BasicDBList expectedlist = new BasicDBList();
    expectedlist.add(new BasicDBObject().append("first1", 1234.0).append("first2", "hello"));
    expectedlist.add(new BasicDBObject().append("first1", 2345.0).append("first2", "hello2"));
    BasicDBObject expected =
        new BasicDBObject().append("stuff", true).append("stuff4", expectedlist);

    BasicDBList actuallist = new BasicDBList();
    actuallist.add(new BasicDBObject().append("first1", 1234.0).append("first2", "hello"));
    actuallist.add(new BasicDBObject().append("first1", 1234213432.0).append("first2", "hello2"));
    BasicDBObject actual = new BasicDBObject().append("stuff", true).append("stuff4", actuallist);

    Assert.assertFalse(expected.equals(actual));
  }
Ejemplo n.º 20
0
  public static BasicDBObject getCloseMeepsQuery(double lat, double longi) {
    BasicDBList coords = new BasicDBList();
    coords.add(longi);
    coords.add(lat);

    BasicDBObject geo = new BasicDBObject();
    geo.append("type", "Point");
    geo.append("coordinates", coords);

    BasicDBObject near = new BasicDBObject();
    near.append("$near", geo);
    near.append("$maxDistance", MIN_MEEP_DISTANCE);

    BasicDBObject loc = new BasicDBObject();
    loc.append("location", near);
    return loc;
  }
Ejemplo n.º 21
0
  @Test
  public void testRoundTrip2() throws Exception {
    System.out.println("testRoundTrip2()");

    BasicDBList list = new BasicDBList();
    list.add("hello");
    list.add("cool");
    BasicDBObject expected = new BasicDBObject().append("stuff", true).append("stuff4", list);
    String json = JsonHelper.toJson(expected);

    Assert.assertEquals("{\"stuff\":true,\"stuff4\":[\"hello\",\"cool\"]}", json);

    BasicDBObject actual = JsonHelper.toJavaMap(json);

    Assert.assertEquals(expected, actual);
    Assert.assertEquals(actual, expected);
  }
Ejemplo n.º 22
0
  private void addNewAdminRolesToMasterRealm(BasicDBObject adminRealm) {
    DBCollection realms = db.getCollection("realms");
    DBCollection applications = db.getCollection("applications");
    DBCollection roles = db.getCollection("roles");

    DBCursor realmsCursor = realms.find();
    try {
      while (realmsCursor.hasNext()) {
        BasicDBObject currentRealm = (BasicDBObject) realmsCursor.next();
        String masterAdminAppName = currentRealm.getString("name") + "-realm";

        BasicDBObject masterAdminApp =
            (BasicDBObject)
                applications.findOne(
                    new BasicDBObject()
                        .append("realmId", adminRealm.get("_id"))
                        .append("name", masterAdminAppName));

        String viewIdProvidersRoleId =
            insertApplicationRole(
                roles, AdminRoles.VIEW_IDENTITY_PROVIDERS, masterAdminApp.getString("_id"));
        String manageIdProvidersRoleId =
            insertApplicationRole(
                roles, AdminRoles.MANAGE_IDENTITY_PROVIDERS, masterAdminApp.getString("_id"));

        BasicDBObject adminRole =
            (BasicDBObject)
                roles.findOne(
                    new BasicDBObject()
                        .append("realmId", adminRealm.get("_id"))
                        .append("name", AdminRoles.ADMIN));
        BasicDBList adminCompositeRoles = (BasicDBList) adminRole.get("compositeRoleIds");
        adminCompositeRoles.add(viewIdProvidersRoleId);
        adminCompositeRoles.add(manageIdProvidersRoleId);
        roles.save(adminRole);

        log.debugv(
            "Added roles {0} and {1} to application {2}",
            AdminRoles.VIEW_IDENTITY_PROVIDERS,
            AdminRoles.MANAGE_IDENTITY_PROVIDERS,
            masterAdminAppName);
      }
    } finally {
      realmsCursor.close();
    }
  }
  public BasicDBList maybeConvertList(Iterable<?> source, TypeInformation<?> typeInformation) {

    BasicDBList newDbl = new BasicDBList();
    for (Object element : source) {
      newDbl.add(convertToMongoType(element, typeInformation));
    }

    return newDbl;
  }
Ejemplo n.º 24
0
 public void perform(BasicDBObjectBuilder builder) {
   BasicDBList list = new BasicDBList();
   for (Operator operator : operators) {
     BasicDBObjectBuilder operatorBuilder = new BasicDBObjectBuilder();
     operator.perform(operatorBuilder);
     list.add(operatorBuilder.get());
   }
   builder.append("$or", list);
 }
Ejemplo n.º 25
0
 public Long getIdest(Long ids, Long ide) {
   try {
     DBObject object = new BasicDBObject();
     BasicDBList list = new BasicDBList();
     list.add(new BasicDBObject("id", new BasicDBObject("$gte", ids)));
     list.add(new BasicDBObject("id", new BasicDBObject("$lt", ide)));
     object.put("$and", list);
     DBObject sort = new BasicDBObject();
     sort.put("id", -1);
     DBCursor cursor = getDBCollection(TABLE_NAME).find(object).sort(sort).limit(1);
     if (cursor.hasNext()) {
       return Long.parseLong(cursor.next().get("id").toString().trim());
     }
   } catch (Exception e) {
     LOG.error(e.getMessage(), e);
   }
   return null;
 }
  /**
   * 查询特定条件文件函数 查询根据 Tags(标签) Tags支持复合条件查询
   *
   * @author felixerio *
   */
  @Override
  public List<YandeCG> querySpecifiedConditionsForTags(List<String> tags) {
    String query[] = tags.toArray(new String[tags.size()]);
    Pattern pattern = Pattern.compile("^.*" + " chikotam" + ".*$", Pattern.CASE_INSENSITIVE);
    Pattern pattern2 = Pattern.compile("^.*" + " minori" + ".*$", Pattern.CASE_INSENSITIVE);

    Pattern pattern3 = Pattern.compile("^.*" + "chikotam " + ".*$", Pattern.CASE_INSENSITIVE);
    Pattern pattern4 = Pattern.compile("^.*" + "minori " + ".*$", Pattern.CASE_INSENSITIVE);

    DBObject queryCondition = new BasicDBObject();
    BasicDBList condList = new BasicDBList();
    queryCondition.put("tags", pattern);
    condList.add(queryCondition);

    DBObject queryCondition2 = new BasicDBObject();
    BasicDBList condList2 = new BasicDBList();
    queryCondition2.put("tags", pattern2);
    condList.add(queryCondition2);

    BasicDBObject searchCond = new BasicDBObject();
    searchCond.put("$and", condList);

    DBCursor cur = collection.find(searchCond);
    logger.info("批量获取指定Tags数据数据任务 查询到 " + cur.size() + " 条数据");
    int num = 1;
    List<YandeCG> yandeCGList = new ArrayList<YandeCG>();
    while (cur.hasNext()) {
      YandeCG yanedCG = new YandeCG();
      DBObject dBObject = cur.next();
      yanedCG.setId(Integer.parseInt(dBObject.get("id").toString()));
      yanedCG.setTags(dBObject.get("tags").toString());
      yanedCG.setMd5(dBObject.get("md5").toString());
      yanedCG.setDownComplete(Boolean.parseBoolean(dBObject.get("downComplete").toString()));
      yanedCG.setSource(dBObject.get("source").toString());
      yanedCG.setFile_url(dBObject.get("file_url").toString());
      yanedCG.setFile_size(dBObject.get("file_size").toString());
      yandeCGList.add(yanedCG);
      logger.info("批量获取指定Tags数据数据任务 完成处理第 " + num + " 个任务");
      num++;
    }
    cur.close();
    return yandeCGList;
  }
  @Override
  public QueryResult next(String chromosome, int position, QueryOptions options) {

    String featureType = options.getString("featureType", null);
    String featureClass = options.getString("featureClass", null);

    BasicDBList chunksId = new BasicDBList();
    String chunkId =
        chromosome
            + "_"
            + getChunkId(position, regulatoryRegionChunkSize)
            + "_"
            + regulatoryRegionChunkSize / 1000
            + "k";
    chunksId.add(chunkId);

    // TODO: Add query to find next item considering next chunk
    // db.regulatory_region.find({ "chromosome" : "19" , "start" : { "$gt" : 62005} , "featureType"
    // : "TF_binding_site_motif"}).sort({start:1}).limit(1)

    QueryBuilder builder;
    if (options.getString("strand") == null
        || (options.getString("strand").equals("1") || options.getString("strand").equals("+"))) {
      // db.core.find({chromosome: "1", start: {$gt: 1000000}}).sort({start: 1}).limit(1)
      builder =
          QueryBuilder.start("_chunkIds")
              .in(chunksId)
              .and("chromosome")
              .is(chromosome)
              .and("start")
              .greaterThan(position);
      options.put("sort", new BasicDBObject("start", 1));
      options.put("limit", 1);
    } else {
      builder =
          QueryBuilder.start("_chunkIds")
              .in(chunksId)
              .and("chromosome")
              .is(chromosome)
              .and("end")
              .lessThan(position);
      options.put("sort", new BasicDBObject("end", -1));
      options.put("limit", 1);
    }

    if (featureType != null) {
      builder.and("featureType").is(featureType);
    }
    if (featureClass != null) {
      builder.and("featureClass").is(featureClass);
    }
    System.out.println(builder.get());
    return executeQuery("result", builder.get(), options);
  }
Ejemplo n.º 28
0
 public List<Admin> findSupports() {
   List<Admin> admins = null;
   try {
     BasicDBList list = new BasicDBList();
     list.add(new BasicDBObject("id", new BasicDBObject("$gte", 40000000L)));
     list.add(new BasicDBObject("id", new BasicDBObject("$lt", 50000000L)));
     DBObject object = new BasicDBObject();
     object.put("$and", list);
     object.put("status", 1);
     DBCursor cursor = getDBCollection(TABLE_NAME).find(object);
     admins = new ArrayList<Admin>();
     while (cursor.hasNext()) {
       Admin admin = getAdminFromResultSet(cursor.next());
       if (admin != null) {
         admins.add(admin);
       }
     }
   } catch (Exception e) {
     LOG.error(e.getMessage(), e);
   }
   return admins;
 }
Ejemplo n.º 29
0
 public BasicDBList saveAll() {
   BasicDBList list = new BasicDBList();
   for (PanelElementAbstract p : panelElements) {
     if (p instanceof PanelElementPlugin) {
       if (((PanelElementPlugin) p).getParameterPanel().getMethod() == null)
         ((PanelElementPlugin) p).setCurrentMethod();
     } else {
       ((ParameterPanel) p.getParameterPanel()).checkValidity();
     }
     list.add(p.getParameterPanel().save());
   }
   return list;
 }
  /**
   * Populates the given {@link BasicDBList} with values from the given {@link Collection}.
   *
   * @param source the collection to create a {@link BasicDBList} for, must not be {@literal null}.
   * @param type the {@link TypeInformation} to consider or {@literal null} if unknown.
   * @param sink the {@link BasicDBList} to write to.
   * @return
   */
  private BasicDBList writeCollectionInternal(
      Collection<?> source, TypeInformation<?> type, BasicDBList sink) {

    TypeInformation<?> componentType = type == null ? null : type.getComponentType();

    for (Object element : source) {

      Class<?> elementType = element == null ? null : element.getClass();

      if (elementType == null || conversions.isSimpleType(elementType)) {
        sink.add(getPotentiallyConvertedSimpleWrite(element));
      } else if (element instanceof Collection || elementType.isArray()) {
        sink.add(writeCollectionInternal(asCollection(element), componentType, new BasicDBList()));
      } else {
        BasicDBObject propDbObj = new BasicDBObject();
        writeInternal(element, propDbObj, componentType);
        sink.add(propDbObj);
      }
    }

    return sink;
  }