/UniwareServices/src/main/java/com/unifier/dao/audit/impl/AuditMaoImpl.java

https://bitbucket.org/piyushgd10/bhumi · Java · 62 lines · 46 code · 9 blank · 7 comment · 5 complexity · 6a96d0f662332d7b1047c03566c60473 MD5 · raw file

  1. /*
  2. * Copyright 2014 Unicommerce eSolutions (P) Limited . All Rights Reserved.
  3. * UNICOMMERCE ESOLUTIONS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. *
  5. * @version 1.0, 23-Apr-2014
  6. * @author parijat
  7. */
  8. package com.unifier.dao.audit.impl;
  9. import java.util.List;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.beans.factory.annotation.Qualifier;
  12. import org.springframework.data.mongodb.core.MongoOperations;
  13. import org.springframework.data.mongodb.core.query.Criteria;
  14. import org.springframework.data.mongodb.core.query.Query;
  15. import org.springframework.stereotype.Repository;
  16. import com.unifier.core.utils.StringUtils;
  17. import com.unifier.dao.audit.IAuditMao;
  18. import com.uniware.core.utils.UserContext;
  19. import com.uniware.core.vo.EntityAuditLogVO;
  20. @Repository
  21. public class AuditMaoImpl implements IAuditMao {
  22. @Autowired
  23. @Qualifier(value = "tenantSpecificMongo")
  24. private MongoOperations mongoOperations;
  25. @Override
  26. public List<EntityAuditLogVO> getEntityAuditById(String entityName, String identifier) {
  27. Query query = new Query(Criteria.where("entityName").is(entityName).and("identifier").is(identifier).orOperator(Criteria.where("entityId").is(identifier)).orOperator(
  28. Criteria.where("groupIdentifier").is(identifier)));
  29. query.addCriteria(Criteria.where("tenantCode").is(UserContext.current().getTenant().getCode()));
  30. query.addCriteria(Criteria.where("facilityCode").is(UserContext.current().getFacility().getCode()).orOperator(Criteria.where("facilityCode").is(null)));
  31. return mongoOperations.find(query, EntityAuditLogVO.class);
  32. }
  33. @Override
  34. public List<EntityAuditLogVO> getEntitiesAuditByTenant(boolean filterByFacility) {
  35. Query query = new Query(Criteria.where("tenantCode").is(UserContext.current().getTenant().getCode()));
  36. if (filterByFacility && UserContext.current().getFacility() != null) {
  37. query.addCriteria(Criteria.where("facilityCode").is(UserContext.current().getFacility().getCode()).orOperator(Criteria.where("facilityCode").is(null)));
  38. }
  39. return mongoOperations.find(query, EntityAuditLogVO.class);
  40. }
  41. @Override
  42. public void save(EntityAuditLogVO entityVO) {
  43. entityVO.setTenantCode(UserContext.current().getTenant().getCode());
  44. entityVO.setFacilityCode(UserContext.current().getFacility().getCode());
  45. if (StringUtils.isNotBlank(UserContext.current().getUniwareUserName())) {
  46. entityVO.setUsername(UserContext.current().getUniwareUserName());
  47. }
  48. if (StringUtils.isNotBlank(UserContext.current().getApiUsername())) {
  49. entityVO.setApiUsername(UserContext.current().getApiUsername());
  50. }
  51. mongoOperations.save(entityVO);
  52. }
  53. }