本文整理匯總了Java中org.bson.types.ObjectId.isValid方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectId.isValid方法的具體用法?Java ObjectId.isValid怎麽用?Java ObjectId.isValid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bson.types.ObjectId
的用法示例。
在下文中一共展示了ObjectId.isValid方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getProductStatusByAgentId
import org.bson.types.ObjectId; //導入方法依賴的package包/類
/**
* 獲取 產品 是否被激活
* 激活的定義為:旗下采集器至少有一個被激活
*
* @param agentId
* @return True 被激活
*/
public Integer getProductStatusByAgentId(String agentId) {
Integer status = null;
if (!ObjectId.isValid(agentId)) {
return null;
}
Document agentDocument = this.database.getCollection("agents")
.find(eq("_id", new ObjectId(agentId)))
.first();
if (agentDocument != null) {
ObjectId productId = agentDocument.getObjectId("product_id");
if (productId != null) {
Document productDocument = this.database.getCollection("products")
.find(eq("_id", productId))
.first();
if (productDocument != null) {
status = productDocument.getInteger("status");
}
}
}
return status;
}
示例2: check
import org.bson.types.ObjectId; //導入方法依賴的package包/類
@GET @Path("{_id}")
@Produces(MediaType.APPLICATION_JSON)
public Response check(@PathParam("_id") String id) {
if (!ObjectId.isValid(id)) {
return Responses.notFound("激活碼無效");
}
Document license = MongoDBs.licenses().find(eq(License._ID, objectId(id))).first();
RebaseAsserts.notNull(license, "license");
return Response.ok(license).build();
}
示例3: active
import org.bson.types.ObjectId; //導入方法依賴的package包/類
@POST @Path("{_id}")
@Produces(MediaType.APPLICATION_JSON)
public Response active(@PathParam("_id") String id, @NotEmpty @QueryParam("device_id") String deviceId) {
if (!ObjectId.isValid(id)) {
return Responses.notFound("激活碼無效");
}
Document license = MongoDBs.licenses().find(eq(License._ID, objectId(id))).first();
RebaseAsserts.notNull(license, "license");
if (!Objects.equals(deviceId, license.getString(License.DEVICE_ID))) {
final Bson target = eq(License._ID, objectId(id));
MongoDBs.licenses().updateOne(target, set(License.DEVICE_ID, deviceId));
license.put(License.DEVICE_ID, deviceId);
}
return Response.ok(license).build();
}
示例4: isAgentdByUser
import org.bson.types.ObjectId; //導入方法依賴的package包/類
/**
* 判斷 采集器 權限
*
* @param id 采集器Id
* @param permission 最低權限
* @return True 權限滿足
*/
public boolean isAgentdByUser(String id, Permission permission) {
if (!ObjectId.isValid(id)) {
return false;
}
return this.database.getCollection("agents")
.find(and(eq("_id", new ObjectId(id)), eq("permissions", new Document("$elemMatch", new Document()
.append("user_id", permission.getUserId())))))
.first() != null;
}
示例5: isAgentExists
import org.bson.types.ObjectId; //導入方法依賴的package包/類
/**
* 判斷Agent是否存在
*
* @param id 采集器Id
* @return 采集器 or Null
*/
public boolean isAgentExists(String id) {
if (!ObjectId.isValid(id)) {
return false;
}
return this.database.getCollection("agents")
.find(eq("_id", new ObjectId(id))).first() != null;
}
示例6: isAgentAuth
import org.bson.types.ObjectId; //導入方法依賴的package包/類
/**
* 判斷Agent是否存在
*
* @param userName 采集器Id
* @return 采集器 or Null
*/
public boolean isAgentAuth(String userName, String password) {
if (!ObjectId.isValid(userName)) {
return false;
}
return this.database.getCollection("agents")
.find(and(eq("_id", new ObjectId(userName)), eq("token", password))).first() != null;
}
示例7: isProductActivated
import org.bson.types.ObjectId; //導入方法依賴的package包/類
/**
* 獲取 產品 是否被激活
* 激活的定義為:旗下采集器至少有一個被激活
*
* @param productId 產品Id
* @return True 被激活
*/
public boolean isProductActivated(String productId) {
if (!ObjectId.isValid(productId)) {
return false;
}
return this.database.getCollection("agents")
.find(and(eq("product_id", new ObjectId(productId)), exists("activated_at", true)))
.projection(include("_id"))
.first() != null;
}
示例8: getOperatorIdByAgent
import org.bson.types.ObjectId; //導入方法依賴的package包/類
/**
* Get Operator Id
*
* @param agentId Agent id
* @return Operator id
*/
public String getOperatorIdByAgent(String agentId) {
if (!ObjectId.isValid(agentId)) {
return null;
}
Document doc = this.database.getCollection("user_assets_info").find(eq("agent_id", new ObjectId(agentId)))
.projection(include("user_id"))
.first();
if (doc == null) return null;
return doc.getObjectId("user_id").toString();
}
示例9: retrieveOccasion
import org.bson.types.ObjectId; //導入方法依賴的package包/類
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response retrieveOccasion(@PathParam("id") String id) {
String method = "retrieveOccasion";
logger.entering(clazz, method, id);
// Validate the JWT. At this point, anyone can get an occasion if they
// have a valid JWT.
try {
validateJWT();
} catch (JWTException jwte) {
logger.exiting(clazz, method, Status.UNAUTHORIZED);
return Response.status(Status.UNAUTHORIZED)
.type(MediaType.TEXT_PLAIN)
.entity(jwte.getMessage())
.build();
}
Response response;
// Ensure we recieved a valid ID
if (!ObjectId.isValid(id)) {
response = Response.status(400).entity("Invalid occasion id").build();
} else {
// perform the query and return the occasion, if we find one
DBObject occasion =
getCollection().findOne(new BasicDBObject(Occasion.OCCASION_ID_KEY, new ObjectId(id)));
logger.fine("In " + method + " with Occasion: \n\n" + occasion);
String occasionJson = new Occasion(occasion).toString();
if (null == occasionJson || occasionJson.isEmpty()) {
response = Response.status(400).entity("no occasion found for given id").build();
} else {
response = Response.ok(occasionJson, MediaType.APPLICATION_JSON).build();
}
}
logger.exiting(clazz, method, response);
return response;
}
示例10: deleteOccasion
import org.bson.types.ObjectId; //導入方法依賴的package包/類
@DELETE
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
public Response deleteOccasion(@PathParam("id") String id) {
String method = "deleteOccasion";
logger.entering(clazz, method, id);
// Validate the JWT. At this point, anyone can delete an occasion
// if they have a valid JWT.
try {
validateJWT();
} catch (JWTException jwte) {
logger.exiting(clazz, method, Status.UNAUTHORIZED);
return Response.status(Status.UNAUTHORIZED)
.type(MediaType.TEXT_PLAIN)
.entity(jwte.getMessage())
.build();
}
Response response;
// Ensure we recieved a valid ID; empty query here deletes everything
if (null == id || id.isEmpty() || !ObjectId.isValid(id)) {
response = Response.status(400).entity("invalid occasion id").build();
} else {
// perform the deletion
if (deleteOccasion(new ObjectId(id)) != true) {
response = Response.status(400).entity("occasion deletion failed").build();
} else {
// Cancel occasion with the orchestrator
orchestrator.cancelOccasion(id);
response = Response.ok().build();
}
}
logger.exiting(clazz, method, response);
return response;
}
示例11: getGroupInfo
import org.bson.types.ObjectId; //導入方法依賴的package包/類
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getGroupInfo(@PathParam("id") String id) {
// Validate the JWT. At this point, anyone can get a group info if they
// have a valid JWT.
try {
validateJWT();
} catch (JWTException jwte) {
return Response.status(Status.UNAUTHORIZED)
.type(MediaType.TEXT_PLAIN)
.entity(jwte.getMessage())
.build();
}
// Check if the id is a valid mongo object id. If not, the server will
// throw a 500
if (!ObjectId.isValid(id)) {
return Response.status(Status.BAD_REQUEST)
.type(MediaType.TEXT_PLAIN)
.entity("The group was not found")
.build();
}
// Query Mongo for group with specified id
BasicDBObject group = (BasicDBObject) getGroupCollection().findOne(new ObjectId(id));
if (group == null) {
return Response.status(Status.BAD_REQUEST)
.type(MediaType.TEXT_PLAIN)
.entity("The group was not found")
.build();
}
// Create a JSON payload with the group content
String responsePayload = (new Group(group)).getJson();
return Response.ok().entity(responsePayload).build();
}
示例12: getGroups
import org.bson.types.ObjectId; //導入方法依賴的package包/類
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getGroups(@QueryParam("userId") String userId) {
// Validate the JWT. At this point, anyone can get a group list if they
// have a valid JWT.
try {
validateJWT();
} catch (JWTException jwte) {
return Response.status(Status.UNAUTHORIZED)
.type(MediaType.TEXT_PLAIN)
.entity(jwte.getMessage())
.build();
}
DBCursor groupCursor = null;
BasicDBList groupList = new BasicDBList();
if (userId != null) {
if (!ObjectId.isValid(userId)) {
return Response.status(Status.BAD_REQUEST)
.type(MediaType.TEXT_PLAIN)
.entity("The user id provided is not valid.")
.build();
}
BasicDBObject queryObj = new BasicDBObject(Group.JSON_KEY_MEMBERS_LIST, userId);
groupCursor = getGroupCollection().find(queryObj);
} else {
groupCursor = getGroupCollection().find();
}
while (groupCursor.hasNext()) {
groupList.add((new Group(groupCursor.next()).getJson()));
}
String responsePayload = (new BasicDBObject(Group.JSON_KEY_GROUPS, groupList)).toString();
return Response.ok(responsePayload).build();
}
示例13: deleteGroup
import org.bson.types.ObjectId; //導入方法依賴的package包/類
@DELETE
@Path("{id}")
public Response deleteGroup(@PathParam("id") String id) {
// Validate the JWT. At this point, anyone can delete 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();
}
// Check if the id is a valid mongo object id. If not, the server will
// throw a 500
if (!ObjectId.isValid(id)) {
return Response.status(Status.BAD_REQUEST)
.type(MediaType.TEXT_PLAIN)
.entity("The group ID is not valid.")
.build();
}
// Query Mongo for group with specified id
BasicDBObject group = (BasicDBObject) getGroupCollection().findOne(new ObjectId(id));
if (group == null) {
return Response.status(Status.BAD_REQUEST)
.type(MediaType.TEXT_PLAIN)
.entity("The group was not found")
.build();
}
// Delete group
getGroupCollection().remove(group);
return Response.ok().build();
}
示例14: updateOccasion
import org.bson.types.ObjectId; //導入方法依賴的package包/類
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateOccasion(@PathParam("id") String id, JsonObject json) {
String method = "updateOccasion";
logger.entering(clazz, method, new Object[] {id, json});
// Validate the JWT. At this point, anyone can update an occasion
// if they have a valid JWT.
try {
validateJWT();
} catch (JWTException jwte) {
logger.exiting(clazz, method, Status.UNAUTHORIZED);
return Response.status(Status.UNAUTHORIZED)
.type(MediaType.TEXT_PLAIN)
.entity(jwte.getMessage())
.build();
}
Response response = Response.ok().build();
// Ensure we recieved a valid ID
if (!ObjectId.isValid(id) || null == json || json.isEmpty()) {
response = Response.status(400).entity("invalid occasion id").build();
} else {
// perform the update using $set to prevent overwriting data in the event of an incomplete
// payload
Occasion updatedOccasion = new Occasion(json);
BasicDBObject updateObject = new BasicDBObject("$set", updatedOccasion.toDbo());
BasicDBObject query = new BasicDBObject(Occasion.OCCASION_ID_KEY, new ObjectId(id));
// Update and return the new document.
DBObject updatedObject =
getCollection().findAndModify(query, null, null, false, updateObject, true, false);
// Reschedule occasion with the orchestrator. Use the updated object from
// mongo because it will contain all fields that the orchestator may need.
try {
orchestrator.cancelOccasion(id);
orchestrator.scheduleOccasion(new Occasion(updatedObject));
} catch (ParseException e) {
e.printStackTrace();
response =
Response.status(400).entity("Invalid date given. Format must be YYYY-MM-DD").build();
}
}
logger.exiting(clazz, method, response);
return response;
}
示例15: setId
import org.bson.types.ObjectId; //導入方法依賴的package包/類
public void setId(String id) {
if (null != id && !id.isEmpty() && ObjectId.isValid(id)) {
this.id = new ObjectId(id);
}
}