www.programcreek.com
Open in
urlscan Pro
2606:4700:20::681a:646
Public Scan
Submitted URL: http://www.programcreek.com/java-api-examples/?class=org.bson.types.ObjectId&method=isValid
Effective URL: https://www.programcreek.com/java-api-examples/?class=org.bson.types.ObjectId&method=isValid
Submission: On September 07 via manual from IN — Scanned from DE
Effective URL: https://www.programcreek.com/java-api-examples/?class=org.bson.types.ObjectId&method=isValid
Submission: On September 07 via manual from IN — Scanned from DE
Form analysis
0 forms found in the DOMText Content
* Search by APIs * Search by Words * Search Projects Most Popular Top Packages Top Classes Top Methods Top Projects * Java * Python * JavaScript * TypeScript * C++ * Scala * Blog report this ad Available Methods * get ( ) * toString ( ) * isValid ( ) Related Classes * java.util.Arrays * java.util.Collections * java.util.Date * java.util.stream.Collectors * java.util.Objects * java.nio.ByteBuffer * org.apache.commons.lang3.StringUtils * org.springframework.web.bind.annotation.RequestMapping * com.google.common.collect.Lists * java.time.LocalDateTime * org.springframework.web.bind.annotation.RequestMethod * org.springframework.http.ResponseEntity * java.time.LocalDate * java.time.ZoneId * javax.ws.rs.core.MediaType * javax.ws.rs.Path * javax.ws.rs.core.Response * javax.ws.rs.GET * javax.ws.rs.Produces * javax.ws.rs.PathParam * javax.ws.rs.Consumes * org.springframework.util.CollectionUtils * org.springframework.data.domain.Sort * javax.ws.rs.core.Response.Status * org.reactivestreams.Publisher JAVA CODE EXAMPLES FOR ORG.BSON.TYPES.OBJECTID#ISVALID() The following examples show how to use org.bson.types.ObjectId#isValid() . 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 Project: sample-acmegifts File: OccasionResource.java License: Eclipse Public License 1.05 votes @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; } Example 2 Source Project: sample-acmegifts File: OccasionResource.java License: Eclipse Public License 1.05 votes @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; } Example 3 Source Project: sample-acmegifts File: GroupResource.java License: Eclipse Public License 1.05 votes @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(); } Example 4 Source Project: sample-acmegifts File: GroupResource.java License: Eclipse Public License 1.05 votes @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(); } Example 5 Source Project: sample-acmegifts File: GroupResource.java License: Eclipse Public License 1.05 votes @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(); } Example 6 Source Project: vertx-mongo-client File: MongoClientImpl.java License: Apache License 2.05 votes JsonObject encodeKeyWhenUseObjectId(JsonObject json) { if (!useObjectId) return json; Object idString = json.getValue(ID_FIELD, null); if (idString instanceof String && ObjectId.isValid((String) idString)) { json.put(ID_FIELD, new JsonObject().put(JsonObjectCodec.OID_FIELD, idString)); } return json; } Example 7 Source Project: sample-acmegifts File: OccasionResource.java License: Eclipse Public License 1.04 votes @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; } Example 8 Source Project: sample-acmegifts File: Occasion.java License: Eclipse Public License 1.04 votes public void setId(String id) { if (null != id && !id.isEmpty() && ObjectId.isValid(id)) { this.id = new ObjectId(id); } } Example 9 Source Project: sample-acmegifts File: Occasion.java License: Eclipse Public License 1.04 votes public BasicDBObject toDbo() { String method = "toDbo"; logger.entering(clazz, method); logger.fine("id: " + id); logger.fine("date: " + date); logger.fine("groupId: " + groupId); logger.fine("interval: " + interval); logger.fine("name: " + name); logger.fine("organizerId: " + organizerId); logger.fine("recipientId: " + recipientId); logger.fine("contributions: " + Contribution.listToString(contributions)); // build the db object BasicDBObject dbo = new BasicDBObject(); if (null != id && ObjectId.isValid(id.toString())) { dbo.append(OCCASION_ID_KEY, id); } if (null != date && !date.isEmpty()) { dbo.append(OCCASION_DATE_KEY, date); } if (null != groupId && !groupId.isEmpty()) { dbo.append(OCCASION_GROUP_ID_KEY, groupId); } if (null != interval && !interval.isEmpty()) { dbo.append(OCCASION_INTERVAL_KEY, interval); } if (null != name && !name.isEmpty()) { dbo.append(OCCASION_NAME_KEY, name); } if (null != organizerId && !organizerId.isEmpty()) { dbo.append(OCCASION_ORGANIZER_ID_KEY, organizerId); } if (null != recipientId && !recipientId.isEmpty()) { dbo.append(OCCASION_RECIPIENT_ID_KEY, recipientId); } BasicDBList contributionDbList = Contribution.listToDBList(contributions); if (null != contributionDbList && !contributionDbList.isEmpty()) { dbo.append(OCCASION_CONTRIBUTIONS_KEY, contributionDbList); } logger.exiting(clazz, method, dbo); return dbo; } Example 10 Source Project: sample-acmegifts File: GroupResource.java License: Eclipse Public License 1.04 votes @PUT @Path("{id}") @Consumes(MediaType.APPLICATION_JSON) public Response updateGroup(@PathParam("id") String id, JsonObject payload) { // Validate the JWT. At this point, anyone can update 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 was not found") .build(); } // Query Mongo for group with specified id BasicDBObject oldGroup = (BasicDBObject) getGroupCollection().findOne(new ObjectId(id)); if (oldGroup == null) { return Response.status(Status.BAD_REQUEST) .type(MediaType.TEXT_PLAIN) .entity("The group was not found") .build(); } // Create new group based on payload content Group updatedGroup = new Group(payload); // Update database with new group getGroupCollection().findAndModify(oldGroup, updatedGroup.getDBObject(true)); return Response.ok().build(); } Example 11 Source Project: jphp File: WrapObjectId.java License: Apache License 2.04 votes @Signature public static boolean isValid(String hexString) { return ObjectId.isValid(hexString); } report this ad EN FR DE ES IT HR SV SR SL NL PRIVACY & TRANSPARENCY We and our partners use cookies to Store and/or access information on a device. We and our partners use data for Personalised ads and content, ad and content measurement, audience insights and product development. An example of data being processed may be a unique identifier stored in a cookie. Some of our partners may process your data as a part of their legitimate business interest without asking for consent. To view the purposes they believe they have legitimate interest for, or to object to this data processing use the vendor list link below. The consent submitted will only be used for data processing originating from this website. If you would like to change your settings or withdraw consent at any time, the link to do so is in our privacy policy accessible from our home page. Manage Settings Allow Necessary Cookies & Continue Continue with Recommended Cookies Vendor List | Privacy Policy