Java Code Examples for com.mongodb.BasicDBObject#getString()

The following examples show how to use com.mongodb.BasicDBObject#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WordCloudGenerator.java    From act with GNU General Public License v3.0 6 votes vote down vote up
public Set<String> getBingInchis() {

    BasicDBObject query = new BasicDBObject("xref.BING.metadata.usage_terms.0", new BasicDBObject(MongoKeywords.EXISTS$.MODULE$.value(), true));
    BasicDBObject keys = new BasicDBObject(ChemicalKeywords.INCHI$.MODULE$.value(), true);

    DBIterator ite = bingDb.getIteratorOverChemicals(query, keys);
    Set<String> bingSet = new HashSet<>();
    while (ite.hasNext()) {
      BasicDBObject o = (BasicDBObject) ite.next();
      String inchi = o.getString(ChemicalKeywords.INCHI$.MODULE$.value());
      if (inchi != null) {
        bingSet.add(inchi);
      }
    }
    return bingSet;
  }
 
Example 2
Source File: User.java    From sample-acmegifts with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isEqual(BasicDBObject other) {
  // Need to get the salt out of the database so we can encode the password.
  String saltString = other.getString("salt");
  if ((saltString == null) || (saltString.length() == 0)) {
    throw new IllegalArgumentException("DB user does not contain a password salt");
  }

  // Now encode the password so we can compare it to what is in the database.
  byte[] salt = Base64.getDecoder().decode(saltString);
  String hashedPassword = null;

  try {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    md.update(salt);
    hashedPassword = Base64.getEncoder().encodeToString(md.digest(this.password.getBytes()));
  } catch (NoSuchAlgorithmException nsae) {
    throw new IllegalStateException();
  }

  return (id.equals(other.getString(DB_ID))
          && firstName.equals(other.get(JSON_KEY_USER_FIRST_NAME))
          && lastName.equals(other.get(JSON_KEY_USER_LAST_NAME))
          && userName.equals(other.get(JSON_KEY_USER_NAME))
          && twitterHandle.equals(other.get(JSON_KEY_USER_TWITTER_HANDLE))
          && wishListLink.equals(other.get(JSON_KEY_USER_WISH_LIST_LINK))
          && hashedPassword.equals(other.get(JSON_KEY_USER_PASSWORD)))
      ? true
      : false;
}
 
Example 3
Source File: GroupResource.java    From sample-acmegifts with Eclipse Public License 1.0 5 votes vote down vote up
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response createGroup(JsonObject payload) {

  // Validate the JWT. At this point, anyone can create a group if they
  // have a valid JWT.
  try {
    validateJWT();
  } catch (JWTException jwte) {
    return Response.status(Status.UNAUTHORIZED)
        .type(MediaType.TEXT_PLAIN)
        .entity(jwte.getMessage())
        .build();
  }

  // Create a new group based on the payload information
  Group newGroup = new Group(payload);

  // Create a db object from the group content and insert it into the
  // collection
  BasicDBObject dbGroup = newGroup.getDBObject(false);
  getGroupCollection().insert(dbGroup);

  // Return the new group id
  JsonObjectBuilder responseBuilder = Json.createObjectBuilder();
  String groupId = dbGroup.getString(Group.DB_ID);
  responseBuilder.add(Group.JSON_KEY_GROUP_ID, groupId);

  JsonObject response = responseBuilder.build();
  return Response.ok(response, MediaType.APPLICATION_JSON).build();
}
 
Example 4
Source File: TransmitterRawData.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public TransmitterRawData(BasicDBObject src) {
	TransmissionId = src.getInt("TransmissionId");
	TransmitterId  = src.getString("TransmitterId");
	RawValue       = src.getInt("RawValue");
	FilteredValue  = src.getInt("FilteredValue");
	BatteryLife    = src.getInt("BatteryLife");
	ReceivedSignalStrength = src.getInt("ReceivedSignalStrength");
	CaptureDateTime = src.getLong("CaptureDateTime");
	UploaderBatteryLife = src.getInt("UploaderBatteryLife");
}
 
Example 5
Source File: LibreWifiData.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public LibreWifiData(BasicDBObject src) {

        BlockBytes = src.getString("BlockBytes");
        CaptureDateTime = src.getLong("CaptureDateTime");
        ChecksumOk = src.getInt("ChecksumOk");
        DebugInfo = src.getString("DebugInfo");
        TomatoBatteryLife = src.getInt("TomatoBatteryLife");
        UploaderBatteryLife = src.getInt("UploaderBatteryLife");
        Uploaded = src.getInt("Uploaded");
        HwVersion = src.getString("HwVersion");
        FwVersion = src.getString("FwVersion");
        SensorId = src.getString("SensorId");
        patchUid = src.getString("patchUid");
        patchInfo = src.getString("patchInfo");
    }
 
Example 6
Source File: TransmitterRawData.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public TransmitterRawData(BasicDBObject src) {
	TransmissionId = src.getInt("TransmissionId");
	TransmitterId  = src.getString("TransmitterId");
	RawValue       = src.getInt("RawValue");
	FilteredValue  = src.getInt("FilteredValue");
	BatteryLife    = src.getInt("BatteryLife");
	ReceivedSignalStrength = src.getInt("ReceivedSignalStrength");
	CaptureDateTime = src.getLong("CaptureDateTime");
	UploaderBatteryLife = src.getInt("UploaderBatteryLife");
}
 
Example 7
Source File: LibreWifiData.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public LibreWifiData(BasicDBObject src) {

        BlockBytes = src.getString("BlockBytes");
        CaptureDateTime = src.getLong("CaptureDateTime");
        ChecksumOk = src.getInt("ChecksumOk");
        DebugInfo = src.getString("DebugInfo");
        TomatoBatteryLife = src.getInt("TomatoBatteryLife");
        UploaderBatteryLife = src.getInt("UploaderBatteryLife");
        Uploaded = src.getInt("Uploaded");
        HwVersion = src.getString("HwVersion");
        FwVersion = src.getString("FwVersion");
        SensorId = src.getString("SensorId");
        patchUid = src.getString("patchUid");
        patchInfo = src.getString("patchInfo");
    }
 
Example 8
Source File: TransmitterRawData.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public TransmitterRawData(BasicDBObject src) {
	TransmissionId = src.getInt("TransmissionId");
	TransmitterId  = src.getString("TransmitterId");
	RawValue       = src.getInt("RawValue");
	FilteredValue  = src.getInt("FilteredValue");
	BatteryLife    = src.getInt("BatteryLife");
	ReceivedSignalStrength = src.getInt("ReceivedSignalStrength");
	CaptureDateTime = src.getLong("CaptureDateTime");
	UploaderBatteryLife = src.getInt("UploaderBatteryLife");
}
 
Example 9
Source File: TransmitterRawData.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public TransmitterRawData(BasicDBObject src) {
	TransmissionId = src.getInt("TransmissionId");
	TransmitterId  = src.getString("TransmitterId");
	RawValue       = src.getInt("RawValue");
	FilteredValue  = src.getInt("FilteredValue");
	BatteryLife    = src.getInt("BatteryLife");
	ReceivedSignalStrength = src.getInt("ReceivedSignalStrength");
	CaptureDateTime = src.getLong("CaptureDateTime");
	UploaderBatteryLife = src.getInt("UploaderBatteryLife");
}
 
Example 10
Source File: Tailer.java    From zerowing with MIT License 5 votes vote down vote up
protected void handleOp(BasicDBObject doc) {
 String type = (String) doc.getString("op"),
        ns = (String) doc.getString("ns");

 updateOptime(doc);

 if (type.equals("n") || type.equals("c")) return;

 String[] parts = ns.split("\\.", 2);
 String database = parts[0], collection = parts[1];
 if (collection.startsWith("system.")) return;

 String tableName = _translator.mapNamespaceToHBaseTable(database, collection);
 HTable table;

 // skip tables that we're skipping
 if (tableName == null) return;

 try {
   table = ensureTable(tableName);
 } catch (Exception e) {
   log.error("Failed to create table " + tableName + " for op: " + doc, e);
   return;
 }

 DBObject data = (DBObject) doc.get("o");
 if (type.equals("i")) {
   handleInsert(table, data);
 } else if (!_skipUpdates && type.equals("u")) {
   DBObject selector = (DBObject) doc.get("o2");
   handleUpdate(table, data, selector, database, collection);
 } else if (!_skipDeletes && type.equals("d")) {
   handleDelete(table, data);
 }
}