/griffin-core/src/main/java/com/ebay/oss/griffin/repo/DqScheudleRepoImpl.java

https://github.com/eBay/griffin · Java · 82 lines · 56 code · 12 blank · 14 comment · 16 complexity · bd2aceb6e25dc5bc086d31fe4a43165c 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.griffin.repo;
  14. import org.springframework.stereotype.Repository;
  15. import com.ebay.oss.griffin.domain.DqSchedule;
  16. import com.ebay.oss.griffin.domain.ModelType;
  17. import com.google.gson.Gson;
  18. import com.mongodb.BasicDBObject;
  19. import com.mongodb.DBObject;
  20. import com.mongodb.util.JSON;
  21. @Repository
  22. public class DqScheudleRepoImpl extends BaseIdRepo<DqSchedule> implements DqScheduleRepo {
  23. public DqScheudleRepoImpl() {
  24. super("dq_schedule", "DQ_JOB_SEQ_NO", DqSchedule.class);
  25. }
  26. @Override
  27. public DBObject getValiditySchedule(long assetId) {
  28. BasicDBObject document = new BasicDBObject();
  29. document.put("assetId", assetId);
  30. document.put("jobType", ModelType.VALIDITY);
  31. return dbCollection.findOne(document);
  32. }
  33. @Override
  34. public void updateByModelType(DqSchedule schedule, int type) {
  35. DBObject dbo = null;
  36. if (type == ModelType.ACCURACY) {
  37. dbo = dbCollection.findOne(new BasicDBObject("modelList", schedule.getModelList()));
  38. } else if (type == ModelType.VALIDITY) {
  39. dbo = getValiditySchedule(schedule.getAssetId());
  40. }
  41. if (dbo != null) {
  42. dbCollection.remove(dbo);
  43. }
  44. Gson gson = new Gson();
  45. DBObject t1 = (DBObject) JSON.parse(gson.toJson(schedule));
  46. dbCollection.save(t1);
  47. }
  48. @Override
  49. public void updateModelType(DBObject schedule, int type) {
  50. DBObject dbo = null;
  51. if (type == ModelType.ACCURACY) {
  52. dbo = dbCollection.findOne(new BasicDBObject("modelList", schedule
  53. .get("modelList")));
  54. } else if (type == ModelType.VALIDITY) {
  55. dbo = getValiditySchedule(Integer.parseInt(schedule.get("assetId").toString()));
  56. }
  57. if (dbo != null)
  58. dbCollection.remove(dbo);
  59. dbCollection.save(schedule);
  60. }
  61. @Override
  62. public void deleteByModelList(String modelList) {
  63. DBObject dbo = dbCollection.findOne(new BasicDBObject("modelList", modelList));
  64. if (dbo != null) {
  65. dbCollection.remove(dbo);
  66. }
  67. }
  68. }