Example usage for com.mongodb.util JSON parse

List of usage examples for com.mongodb.util JSON parse

Introduction

In this page you can find the example usage for com.mongodb.util JSON parse.

Prototype

public static Object parse(final String jsonString) 

Source Link

Document

Parses a JSON string and returns a corresponding Java object.

Usage

From source file:com.shampan.model.PageModel.java

public ResultEvent addAlbumLikeByReferenceId(String referenceId, String likeInfo) {
    try {/*from  w w  w  .jav a 2 s  . c o  m*/
        MongoCollection<PageAlbumDAO> mongoCollection = DBConnection.getInstance().getConnection()
                .getCollection(Collections.PAGEALBUMS.toString(), PageAlbumDAO.class);
        String attrReferenceId = PropertyProvider.get("REFERENCE_ID");
        String attrLike = PropertyProvider.get("LIKE");
        BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start(attrReferenceId).is(referenceId).get();
        Like albumlikeInfo = Like.getLikeInfo(likeInfo);
        if (albumlikeInfo != null) {
            mongoCollection.findOneAndUpdate(selectQuery,
                    new Document("$push", new Document(attrLike, JSON.parse(albumlikeInfo.toString()))));
            this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION"));
        }
    } catch (Exception ex) {
        this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION"));
    }
    return this.resultEvent;
}

From source file:com.shampan.model.PageModel.java

public ResultEvent addAlbumCommentByReferenceId(String referenceId, String commentInfo) {
    try {/*  www. ja  v  a2 s .  com*/
        MongoCollection<PagePhotoDAO> mongoCollection = DBConnection.getInstance().getConnection()
                .getCollection(Collections.PAGEALBUMS.toString(), PagePhotoDAO.class);
        BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("referenceId").is(referenceId).get();
        Comment photoCommentInfo = Comment.getCommentInfo(commentInfo);
        if (photoCommentInfo != null) {
            photoCommentInfo.setCreatedOn(utility.getCurrentTime());
            mongoCollection.findOneAndUpdate(selectQuery,
                    new Document("$push", new Document("comment", JSON.parse(photoCommentInfo.toString()))));
            this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION"));
        }
    } catch (Exception ex) {
        this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION"));
    }
    return this.resultEvent;
}

From source file:com.shampan.model.PageModel.java

public ResultEvent addPhotoLikeByReferenceId(String referenceId, String likeInfo) {
    try {/*from  w  w w . j  a va 2  s  .  com*/
        MongoCollection<PagePhotoDAO> mongoCollection = DBConnection.getInstance().getConnection()
                .getCollection(Collections.PAGEPHOTOS.toString(), PagePhotoDAO.class);
        String attrReferenceId = PropertyProvider.get("REFERENCE_ID");
        String attrLike = PropertyProvider.get("LIKE");
        BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start(attrReferenceId).is(referenceId).get();
        Like photoLikeInfo = Like.getLikeInfo(likeInfo);
        if (photoLikeInfo != null) {
            mongoCollection.findOneAndUpdate(selectQuery,
                    new Document("$push", new Document(attrLike, JSON.parse(photoLikeInfo.toString()))));
            this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION"));
        }
    } catch (Exception ex) {
        this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION"));
    }
    return this.resultEvent;
}

From source file:com.shampan.model.PageModel.java

public ResultEvent addPhotoLike(String photoId, String likeInfo) {
    try {//from  ww w .  ja  v  a 2  s . c  o  m
        MongoCollection<PagePhotoDAO> mongoCollection = DBConnection.getInstance().getConnection()
                .getCollection(Collections.PAGEPHOTOS.toString(), PagePhotoDAO.class);
        BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("photoId").is(photoId).get();
        Like photoLikeInfo = Like.getLikeInfo(likeInfo);
        if (photoLikeInfo != null) {
            mongoCollection.findOneAndUpdate(selectQuery,
                    new Document("$push", new Document("like", JSON.parse(photoLikeInfo.toString()))));
            this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION"));
        }
    } catch (Exception ex) {
        this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION"));
    }
    return this.resultEvent;
}

From source file:com.shampan.model.PageModel.java

public ResultEvent addMPhotoLike(String userId, String photoId, String likeInfo) {
    try {/*from w w  w. j av a2s .  c o m*/
        MongoCollection<PagePhotoDAO> mongoCollection = DBConnection.getInstance().getConnection()
                .getCollection(Collections.PAGEPHOTOS.toString(), PagePhotoDAO.class);
        BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("photoId").is(photoId).get();
        Like photoLikeInfo = Like.getLikeInfo(likeInfo);
        if (photoLikeInfo != null) {
            mongoCollection.findOneAndUpdate(selectQuery,
                    new Document("$set", new Document("modifiedOn", utility.getCurrentTime())));
            mongoCollection.findOneAndUpdate(selectQuery,
                    new Document("$push", new Document("like", JSON.parse(photoLikeInfo.toString()))));
            UserInfo userInfo = photoLikeInfo.getUserInfo();
            notificationModel.addGeneralNotificationPagePhotoLike(userId, photoId, userInfo.toString());
            this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION"));
        }
    } catch (Exception ex) {
        this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION"));
    }
    return this.resultEvent;
}

From source file:com.shampan.model.PageModel.java

public ResultEvent addPhotoCommentByReferenceId(String referenceId, String commentInfo) {
    try {/*from   w w w . j  a  v a2s  .  co m*/
        MongoCollection<PagePhotoDAO> mongoCollection = DBConnection.getInstance().getConnection()
                .getCollection(Collections.PAGEPHOTOS.toString(), PagePhotoDAO.class);
        BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("referenceId").is(referenceId).get();
        Comment photoCommentInfo = Comment.getCommentInfo(commentInfo);
        if (photoCommentInfo != null) {
            photoCommentInfo.setCreatedOn(utility.getCurrentTime());
            mongoCollection.findOneAndUpdate(selectQuery,
                    new Document("$push", new Document("comment", JSON.parse(photoCommentInfo.toString()))));
            this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION"));
        }
    } catch (Exception ex) {
        this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION"));
    }
    return this.resultEvent;
}

From source file:com.shampan.model.PageModel.java

public ResultEvent addPhotoComment(String photoId, String commentInfo) {
    try {/*from  ww w .  j  av a  2  s  .c  o m*/
        MongoCollection<PagePhotoDAO> mongoCollection = DBConnection.getInstance().getConnection()
                .getCollection(Collections.PAGEPHOTOS.toString(), PagePhotoDAO.class);
        BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("photoId").is(photoId).get();
        Comment photoCommentInfo = Comment.getCommentInfo(commentInfo);
        if (photoCommentInfo != null) {
            photoCommentInfo.setCreatedOn(utility.getCurrentTime());
            mongoCollection.findOneAndUpdate(selectQuery,
                    new Document("$push", new Document("comment", JSON.parse(photoCommentInfo.toString()))));
            this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION"));
        }
    } catch (Exception ex) {
        this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION"));
    }
    return this.resultEvent;
}

From source file:com.shampan.model.VideoModel.java

public String addVideoLike(String videoId, String likeInfo) {
    MongoCollection<VideoDAO> mongoCollection = DBConnection.getInstance().getConnection()
            .getCollection(Collections.VIDEOS.toString(), VideoDAO.class);
    BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("videoId").is(videoId).get();
    Like videolikeInfo = Like.getLikeInfo(likeInfo);
    if (videolikeInfo != null) {
        VideoDAO result = mongoCollection.findOneAndUpdate(selectQuery,
                new Document("$push", new Document("like", JSON.parse(videolikeInfo.toString()))));
        resultEvent.setResponseCode(PropertyProvider.get("Created"));
        return resultEvent.toString();
    } else {/*from  w  ww .j ava 2  s . co m*/
        resultEvent.setResponseCode(PropertyProvider.get("BadRequest"));
        return resultEvent.toString();

    }
}

From source file:com.shampan.model.VideoModel.java

public String addVideoComment(String videoId, String commentInfo) {
    MongoCollection<VideoDAO> mongoCollection = DBConnection.getInstance().getConnection()
            .getCollection(Collections.VIDEOS.toString(), VideoDAO.class);
    BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("videoId").is(videoId).get();
    Comment videoCommentInfo = Comment.getCommentInfo(commentInfo);
    try {/*ww  w  . j av  a2  s  .c  o  m*/
        if (videoCommentInfo != null) {
            VideoDAO result = mongoCollection.findOneAndUpdate(selectQuery,
                    new Document("$push", new Document("comment", JSON.parse(videoCommentInfo.toString()))));
            if (result != null) {
                resultEvent.setResponseCode(PropertyProvider.get("Created"));
                return resultEvent.toString();
            }
        }
    } catch (NullPointerException npe) {
        LogWriter.getErrorLog().error("null value exception");
    }
    resultEvent.setResponseCode(PropertyProvider.get("BadRequest"));
    return resultEvent.toString();
}

From source file:com.smbtec.xo.mongodb.impl.JSONQuery.java

License:Apache License

private ResultIterator<Map<String, Object>> execute0(String json, Class<?> type,
        Map<String, Object> parameters) {
    // TODO//from ww w .  ja va2  s  .com
    DBCollection collection = database.getCollection("A");

    final DBCursor matches = collection.find((DBObject) JSON.parse(json));

    return new ResultIterator<Map<String, Object>>() {

        public boolean hasNext() {
            return matches.hasNext();
        }

        public Map<String, Object> next() {
            DBObject next = matches.next();
            final Map<String, Object> result = new HashMap<>();
            // TODO
            result.put("result", new MongoDbDocument(next, "A"));
            return result;
        }

        public void remove() {
            throw new XOException("Remove operation is not supported for query results.");
        }

        public void close() {
            matches.close();
        }
    };

}