当前位置: 首页>>代码示例>>Java>>正文


Java ObjectId.isValid方法代码示例

本文整理汇总了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;
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:30,代码来源:MongoStorage.java

示例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();
}
 
开发者ID:drakeet,项目名称:rebase-server,代码行数:11,代码来源:LicenseV2Resource.java

示例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();
}
 
开发者ID:drakeet,项目名称:rebase-server,代码行数:16,代码来源:LicenseV2Resource.java

示例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;
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:17,代码来源:MongoStorage.java

示例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;
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:14,代码来源:MongoStorage.java

示例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;
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:14,代码来源:MongoStorage.java

示例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;

}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:18,代码来源:MongoStorage.java

示例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();
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:17,代码来源:MongoStorage.java

示例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;
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:40,代码来源:OccasionResource.java

示例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;
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:39,代码来源:OccasionResource.java

示例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();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:41,代码来源:GroupResource.java

示例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();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:40,代码来源:GroupResource.java

示例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();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:40,代码来源:GroupResource.java

示例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;
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:50,代码来源:OccasionResource.java

示例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);
  }
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:6,代码来源:Occasion.java


注:本文中的org.bson.types.ObjectId.isValid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。