Java Code Examples for org.bson.types.ObjectId#toString()
The following examples show how to use
org.bson.types.ObjectId#toString() .
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: MongoDataHandler.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * This method inserts a given entity to the given collection. * * @param tableName Name of the table * @param entity Entity * @throws ODataServiceFault */ @Override public ODataEntry insertEntityToTable(String tableName, ODataEntry entity) { ODataEntry createdEntry = new ODataEntry(); final Document document = new Document(); for (String columnName : entity.getData().keySet()) { String columnValue = entity.getValue(columnName); document.put(columnName, columnValue); entity.addValue(columnName, columnValue); } ObjectId objectId = new ObjectId(); document.put(DOCUMENT_ID, objectId); jongo.getCollection(tableName).insert(document); String documentIdValue = objectId.toString(); createdEntry.addValue(DOCUMENT_ID, documentIdValue); //Set Etag to the entity createdEntry.addValue(ODataConstants.E_TAG, ODataUtils.generateETag(this.configId, tableName, entity)); return createdEntry; }
Example 2
Source File: GroupResourceTest.java From sample-acmegifts with Eclipse Public License 1.0 | 6 votes |
/** * Add a new group object to the database. Call PUT using the id of the new mongo object to update * the group information (name, members list, occasions list). Verify that the group information * has been updated * * @throws GeneralSecurityException */ @Test public void testUpdateGroup() throws IOException, GeneralSecurityException { System.out.println("\nStarting testUpdateGroup"); // Create group in database Group group = new Group(null, "testGroup", new String[] {"12345", "23456"}); BasicDBObject dbGroup = group.getDBObject(false); db.getCollection(Group.DB_COLLECTION_NAME).insert(dbGroup); group.setId(dbGroup.getObjectId(Group.DB_ID).toString()); // Create updated group ObjectId groupId = dbGroup.getObjectId(Group.DB_ID); Group newGroup = new Group(groupId.toString(), "newTestGroup", new String[] {"12345"}); String url = groupServiceURL + "/" + groupId; makeConnection("PUT", url, newGroup.getJson(), 200); // Verify that the new group information is in mongo BasicDBObject newDBGroup = (BasicDBObject) db.getCollection("groups").findOne(groupId); assertNotNull("Group testGroup was not found in the database.", newDBGroup); assertTrue( "Group in database does not contain the expected data", newGroup.isEqual(newDBGroup)); }
Example 3
Source File: MongoDBTestHelper.java From brooklyn-library with Apache License 2.0 | 5 votes |
/** * Inserts a new object with { key: value } at given server. * @return The new document's id */ public static String insert(AbstractMongoDBServer entity, String key, Object value) { LOG.info("Inserting {}:{} at {}", new Object[]{key, value, entity}); MongoClient mongoClient = clientForServer(entity); try { DB db = mongoClient.getDB(TEST_DB); DBCollection testCollection = db.getCollection(TEST_COLLECTION); BasicDBObject doc = new BasicDBObject(key, value); testCollection.insert(doc); ObjectId id = (ObjectId) doc.get("_id"); return id.toString(); } finally { mongoClient.close(); } }
Example 4
Source File: StackMetaDataService.java From render with GNU General Public License v2.0 | 5 votes |
@Path("v1/likelyUniqueId") @GET @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "A (very likely) globally unique identifier") public String getUniqueId() { final ObjectId objectId = new ObjectId(); return objectId.toString(); }
Example 5
Source File: ArticleService.java From jakduk-api with MIT License | 5 votes |
/** * BoardLogs 생성 */ private List<BoardLog> initBoardLogs(ObjectId objectId, String type, CommonWriter writer) { List<BoardLog> logs = new ArrayList<>(); BoardLog history = new BoardLog(objectId.toString(), type, new SimpleWriter(writer.getUserId(), writer.getUsername())); logs.add(history); return logs; }
Example 6
Source File: VideoService.java From tutorials with MIT License | 5 votes |
public String addVideo(String title, MultipartFile file) throws IOException { DBObject metaData = new BasicDBObject(); metaData.put("type", "video"); metaData.put("title", title); ObjectId id = gridFsTemplate.store(file.getInputStream(), file.getName(), file.getContentType(), metaData); return id.toString(); }
Example 7
Source File: ObjectIdSerializer.java From xian with Apache License 2.0 | 4 votes |
@Override public void write(JSONSerializer serializer, Object valueObject, Object fieldName, Type fieldType, int features) throws IOException { ObjectId value = (ObjectId) valueObject; String id = value.toString(); serializer.write(id); }
Example 8
Source File: MongoResourceStorage.java From EDDI with Apache License 2.0 | 4 votes |
@Override public String getId() { Document idObject = (Document) doc.get(ID_FIELD); ObjectId id = (ObjectId) idObject.get(ID_FIELD); return id.toString(); }
Example 9
Source File: ArticleService.java From jakduk-api with MIT License | 4 votes |
/** * 자유게시판 글 지움 * * @param board 게시판 * @param seq 글 seq * @return Constants.ARTICLE_DELETE_TYPE */ public Constants.ARTICLE_DELETE_TYPE deleteArticle(CommonWriter writer, Constants.BOARD_TYPE board, Integer seq) { Article article = articleRepository.findOneByBoardAndSeq(board.name(), seq) .orElseThrow(() -> new ServiceException(ServiceError.NOT_FOUND_ARTICLE)); if (! article.getWriter().getUserId().equals(writer.getUserId())) throw new ServiceException(ServiceError.FORBIDDEN); ArticleItem articleItem = new ArticleItem(article.getId(), article.getSeq(), article.getBoard()); Integer count = articleCommentRepository.countByArticle(articleItem); // 댓글이 하나라도 달리면 글을 몽땅 지우지 못한다. if (count > 0) { article.setContent(null); article.setSubject(null); article.setWriter(null); List<BoardLog> histories = article.getLogs(); if (Objects.isNull(histories)) histories = new ArrayList<>(); ObjectId boardHistoryId = new ObjectId(); BoardLog history = new BoardLog(boardHistoryId.toString(), Constants.ARTICLE_LOG_TYPE.DELETE.name(), new SimpleWriter(writer.getUserId(), writer.getUsername())); histories.add(history); article.setLogs(histories); ArticleStatus articleStatus = article.getStatus(); if (Objects.isNull(articleStatus)) articleStatus = new ArticleStatus(); articleStatus.setDelete(true); article.setStatus(articleStatus); article.setLinkedGallery(false); // lastUpdated article.setLastUpdated(LocalDateTime.ofInstant(boardHistoryId.getDate().toInstant(), ZoneId.systemDefault())); articleRepository.save(article); log.info("A post was deleted(post only). post seq={}, subject={}", article.getSeq(), article.getSubject()); } // 몽땅 지우기 else { articleRepository.delete(article); log.info("A post was deleted(all). post seq={}, subject={}", article.getSeq(), article.getSubject()); } // 연결된 사진 끊기 if (article.getLinkedGallery()) commonGalleryService.unlinkGalleries(article.getId(), Constants.GALLERY_FROM_TYPE.ARTICLE); // 색인 지움 rabbitMQPublisher.deleteDocumentArticle(article.getId()); return count > 0 ? Constants.ARTICLE_DELETE_TYPE.CONTENT : Constants.ARTICLE_DELETE_TYPE.ALL; }
Example 10
Source File: ObjectIdTypeHandler.java From mongodb-orm with Apache License 2.0 | 4 votes |
@Override public Object resovleValue(ObjectId target) { return target.toString(); }