/bark-core/src/main/java/com/ebay/oss/bark/repo/UserSubscriptionRepoImpl.java

https://github.com/zlfsimon/DQSolution · Java · 60 lines · 35 code · 11 blank · 14 comment · 6 complexity · ee0a13994c4e7f99308c91f55d5f2de6 MD5 · raw file

  1. /*
  2. Copyright (c) 2016 eBay Software Foundation.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.ebay.oss.bark.repo;
  14. import org.springframework.stereotype.Repository;
  15. import com.ebay.oss.bark.domain.UserSubscription;
  16. import com.google.gson.Gson;
  17. import com.mongodb.BasicDBObject;
  18. import com.mongodb.DBObject;
  19. import com.mongodb.util.JSON;
  20. @Repository
  21. public class UserSubscriptionRepoImpl extends BaseRepo<UserSubscription>
  22. implements UserSubscriptionRepo {
  23. private UserSubscriptionRepoImpl() {
  24. super("user_subscribe", UserSubscription.class);
  25. }
  26. @Override
  27. public void upsertUserSubscribe(UserSubscription item) {
  28. if (item.getNtaccount() == null)
  29. return;
  30. item.setId(item.getNtaccount());// user_subscribe
  31. DBObject find = dbCollection.findOne(new BasicDBObject("_id", item.getId()));
  32. if (find != null)
  33. dbCollection.remove(find);
  34. Gson gson = new Gson();
  35. DBObject t1 = (DBObject) JSON.parse(gson.toJson(item));
  36. dbCollection.save(t1);
  37. }
  38. @Override
  39. public UserSubscription getUserSubscribeItem(String user) {
  40. Gson gson = new Gson();
  41. DBObject find = dbCollection.findOne(new BasicDBObject("_id", user));
  42. if (find == null)
  43. return null;
  44. else
  45. return gson.fromJson(find.toString(), UserSubscription.class);
  46. }
  47. }