Java Code Examples for com.mongodb.BasicDBList#contains()

The following examples show how to use com.mongodb.BasicDBList#contains() . 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: UserResource.java    From XBDD with Apache License 2.0 5 votes vote down vote up
private void updateIgnoredTag(final BasicDBObject documentToUpdate, final String tagName) {
	final BasicDBList tags = (BasicDBList) documentToUpdate.get("tags");
	if (tags.contains(tagName)) {
		tags.remove(tagName);
	} else {
		tags.add(tagName);
	}
}
 
Example 2
Source File: Recents.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@PUT
@Path("/feature/{product}/{major}.{minor}.{servicePack}/{build}/{id:.+}")
@Produces(MediaType.APPLICATION_JSON)
public Response addFeatureToRecents(@QueryParam("name") final String featureName,
		@BeanParam final Coordinates coordinates,
		@PathParam("id") final String featureID) {

	final BasicDBObject featureDetails = new BasicDBObject("name", featureName);
	featureDetails.put("product", coordinates.getProduct());
	featureDetails.put("version", coordinates.getVersionString());
	featureDetails.put("build", coordinates.getBuild());
	featureDetails.put("id", featureID);

	final DBCollection collection = this.mongoLegacyDb.getCollection("users");

	final BasicDBObject user = new BasicDBObject();
	user.put("user_id", LoggedInUserUtil.getLoggedInUser().getUserId());

	final DBObject blank = new BasicDBObject();
	final DBObject doc = collection.findAndModify(user, blank, blank, false, new BasicDBObject("$set", user), true, true);

	if (doc.containsField("recentFeatures")) {
		final BasicDBList featureArray = (BasicDBList) doc.get("recentFeatures");
		if (featureArray.contains(featureDetails)) {
			featureArray.remove(featureDetails);
			featureArray.add(featureDetails);
			collection.update(user, new BasicDBObject("$set", new BasicDBObject("recentFeatures", featureArray)));
		} else {
			if (featureArray.size() >= 5) {
				collection.update(user, new BasicDBObject("$pop", new BasicDBObject("recentFeatures", "-1")));
			}
			collection.update(user, new BasicDBObject("$addToSet", new BasicDBObject("recentFeatures", featureDetails)));
		}
	} else {
		collection.update(user, new BasicDBObject("$addToSet", new BasicDBObject("recentFeatures", featureDetails)));
	}

	return Response.ok().build();
}
 
Example 3
Source File: Recents.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@PUT
@Path("/build/{product}/{major}.{minor}.{servicePack}/{build}")
@Produces(MediaType.APPLICATION_JSON)
public Response addBuildToRecents(@BeanParam final Coordinates coordinates) {

	final DBObject buildCoords = coordinates.getReportCoordinates();

	final DBCollection collection = this.mongoLegacyDb.getCollection("users");

	final BasicDBObject user = new BasicDBObject();
	user.put("user_id", LoggedInUserUtil.getLoggedInUser().getUserId());

	final DBObject blank = new BasicDBObject();
	final DBObject doc = collection.findAndModify(user, blank, blank, false, new BasicDBObject("$set", user), true, true);

	if (doc.containsField("recentBuilds")) {
		final BasicDBList buildArray = (BasicDBList) doc.get("recentBuilds");
		if (buildArray.contains(buildCoords)) {
			// BasicDBObject toMove = (BasicDBObject) featureArray.get(featureArray.indexOf(featureDetails));
			buildArray.remove(buildCoords);
			buildArray.add(buildCoords);
			collection.update(user, new BasicDBObject("$set", new BasicDBObject("recentBuilds", buildArray)));
		} else {
			if (buildArray.size() >= 5) {
				collection.update(user, new BasicDBObject("$pop", new BasicDBObject("recentBuilds", "-1")));
			}
			collection.update(user, new BasicDBObject("$addToSet", new BasicDBObject("recentBuilds", buildCoords)));
		}
	} else {
		collection.update(user, new BasicDBObject("$addToSet", new BasicDBObject("recentBuilds", buildCoords)));
	}

	return Response.ok().build();
}