Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. package id.co.sts.firebase.bo.device;
  2.  
  3. import id.co.sts.firebase.dao.DeviceDao;
  4. import id.co.sts.firebase.dao.DeviceLogDao;
  5. import id.co.sts.firebase.entity.Device;
  6. import id.co.sts.firebase.entity.DeviceLog;
  7.  
  8. import org.jleaf.core.BusinessFunction;
  9. import org.jleaf.core.BusinessTransaction;
  10. import org.jleaf.core.DefaultBusinessTransaction;
  11. import org.jleaf.core.Dto;
  12. import org.jleaf.core.GeneralConstants;
  13. import org.jleaf.core.annotation.ErrorList;
  14. import org.jleaf.core.annotation.Info;
  15. import org.jleaf.core.annotation.InfoIn;
  16. import org.jleaf.core.annotation.InfoOut;
  17. import org.jleaf.util.GsonUtil;
  18. import org.jleaf.util.ValidationUtil;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.beans.factory.annotation.Qualifier;
  23. import org.springframework.stereotype.Service;
  24.  
  25. @Service
  26. @InfoIn(value = {
  27. @Info(name="projectId", description="Project id", type=String.class, required=true),
  28. @Info(name="uuid", description="user uid", type=Long.class, required=true)
  29. })
  30. @InfoOut(value = {
  31. @Info(name = "id", description = "device id", type = Long.class),
  32. @Info(name = "tenantId", description = "tenant id", type = Long.class),
  33. @Info(name = "projectId", description = "project id", type = Long.class),
  34. @Info(name = "uuid", description = "user uid", type = String.class),
  35. @Info(name = "refCode", description = "ref code", type = String.class),
  36. @Info(name = "token", description = "token", type = String.class),
  37. @Info(name = "createDateTime", description = "create date time", type = String.class),
  38. @Info(name = "updateDateTime", description = "update date time", type = String.class),
  39. @Info(name = "createUserId", description = "create user id", type = Long.class),
  40. @Info(name = "updateUserId", description = "update user id", type = Long.class),
  41. @Info(name = "version", description = "version", type = Long.class),
  42. @Info(name = "active", description = "active", type = String.class),
  43. @Info(name = "activeDateTime", description = "active date time", type = String.class),
  44. @Info(name = "nonActiveDateTime", description = "non active date time", type = String.class)
  45. })
  46. @ErrorList(errorKeys = {})
  47.  
  48. public class InactiveDevice extends DefaultBusinessTransaction implements BusinessTransaction{
  49.  
  50. private final static Logger log = LoggerFactory.getLogger(AddOrEditDevice.class);
  51.  
  52. @Autowired
  53. DeviceDao deviceDao;
  54.  
  55. @Autowired
  56. DeviceLogDao deviceLogDao;
  57.  
  58. @Autowired
  59. @Qualifier("findDeviceByIndex")
  60. BusinessFunction findDeviceByIndex;
  61.  
  62. public String getDescription() {
  63. // TODO Auto-generated method stub
  64. return "Inactive Device";
  65. }
  66.  
  67. @Override
  68. public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  69. // TODO Auto-generated method stub
  70. ValidationUtil.valBlankOrNull(inputDto, "projectId");
  71. ValidationUtil.valBlankOrNull(inputDto, "uuid");
  72. ValidationUtil.valBlankOrNull(inputDto, "active");
  73.  
  74. log.debug("Call find device by index");
  75. log.debug("Input : "+inputDto);
  76.  
  77. Dto outputFindDeviceByIndex = findDeviceByIndex.execute(inputDto);
  78. Long projectId = outputFindDeviceByIndex.getLong("projectId");
  79. inputDto.put("projectId", projectId);
  80.  
  81. log.debug("Output: ");
  82. log.debug(outputFindDeviceByIndex.toString());
  83.  
  84. Dto device = new Dto();
  85. device.put("projectId", projectId);
  86. device.put("uuid", inputDto.get("uuid"));
  87. device.put("active", inputDto.get("active"));
  88.  
  89. this.prepareInsertAudit(device, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
  90. this.prepareUpdateAudit(device, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
  91.  
  92. inputDto.put("device", device);
  93.  
  94. return null;
  95. }
  96.  
  97. @Override
  98. public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  99. Dto deviceDto = inputDto.getDto("device");
  100.  
  101. Device device;
  102.  
  103. DeviceLog deviceLog;
  104.  
  105. if(GeneralConstants.YES.equals(deviceDto.get("active"))){
  106. deviceDto.put("active", GeneralConstants.NO);
  107. }
  108.  
  109. log.debug("Before merge");
  110. log.debug(deviceDto.toString());
  111.  
  112. device = GsonUtil.fromDto(deviceDto, Device.class);
  113. deviceDao.merge(deviceDto.getLong("id"),device);
  114. deviceDao.flush();
  115.  
  116. deviceDto.put("deviceId", deviceDto.getLong("id"));
  117. deviceLog = GsonUtil.fromDto(deviceDto, DeviceLog.class);
  118. deviceLog.setId(null);
  119.  
  120. log.debug("Device log");
  121. log.debug(deviceLog.toString());
  122.  
  123.  
  124. deviceLogDao.persist(deviceLog);
  125. deviceLogDao.flush();
  126.  
  127.  
  128. return new Dto(device);
  129. }
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement