Fanadia_Friska

ADD REGION CUSTOMER SING SUI

Sep 21st, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. package org.jleaf.erp.master.bo.customervsrayon;
  2.  
  3. import org.jleaf.core.BusinessFunction;
  4. import org.jleaf.core.BusinessTransaction;
  5. import org.jleaf.core.CoreException;
  6. import org.jleaf.core.DefaultBusinessTransaction;
  7. import org.jleaf.core.Dto;
  8. import org.jleaf.core.annotation.ErrorList;
  9. import org.jleaf.core.annotation.Info;
  10. import org.jleaf.core.annotation.InfoIn;
  11. import org.jleaf.core.annotation.InfoOut;
  12. import org.jleaf.erp.master.MasterExceptionConstantsForDlg;
  13. import org.jleaf.erp.master.dao.RegionCustomerDao;
  14. import org.jleaf.erp.master.entity.RegionCustomer;
  15. import org.jleaf.util.GsonUtil;
  16. import org.jleaf.util.ValidationUtil;
  17. import org.slf4j.Logger;
  18. import org.slf4j.LoggerFactory;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.beans.factory.annotation.Qualifier;
  21. import org.springframework.stereotype.Service;
  22.  
  23. /**
  24. *
  25. * BT Add Region Customer
  26. *
  27. * @author Nadia, Sept 14, 2016
  28. *
  29. */
  30.  
  31. @Service
  32. @InfoIn(value = {
  33. @Info(name = "tenantLoginId", description = "tenant login id", type = Long.class),
  34. @Info(name = "roleLoginId", description = "role login id", type = Long.class),
  35. @Info(name = "userLoginId", description = "user Id", type = Long.class),
  36. @Info(name = "datetime", description = "datetime", type = String.class),
  37.  
  38. @Info(name = "regionId", description = "region Id", type = Long.class),
  39. @Info(name = "customerId", description = "customer Id", type = Long.class)
  40.  
  41. })
  42. //@InfoOut(value = { @Info(name = "regionCustomerList", description = "region customer list("
  43. // + " id, tenantId, regionId, customerId,"
  44. // + " createDatetime, updateDatetime, createUserId, "
  45. // + " updateUserId, version ))") })
  46. @InfoOut(value = {
  47. @Info(name = "id", description = "id", type = Long.class),
  48. @Info(name = "tenantId", description = "tenantId", type = Long.class),
  49. @Info(name = "regionId", description = "id", type = Long.class),
  50. @Info(name = "customerId", description = "id", type =Long.class),
  51. @Info(name = "createDateTime", description = "create date time", type =
  52. String.class),
  53. @Info(name = "updateDateTime", description = "update date time", type =
  54. String.class),
  55. @Info(name = "createUserId", description = "create user id", type =
  56. Long.class),
  57. @Info(name = "updateUserId", description = "update user id", type =
  58. Long.class),
  59. @Info(name = "version", description = "version", type = String.class)
  60.  
  61. })
  62. @ErrorList(errorKeys = { MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS })
  63. public class AddRegionCustomer extends DefaultBusinessTransaction implements
  64. BusinessTransaction {
  65. private static final Logger log = LoggerFactory
  66. .getLogger(AddRegionCustomer.class);
  67.  
  68. @Autowired
  69. @Qualifier("findRegionCustomerByIndex")
  70. private BusinessFunction findRegionCustomerByIndex;
  71.  
  72. @Autowired
  73. @Qualifier("isRegionCustomerExistsByIndex")
  74. BusinessFunction isRegionCustomerExistsByIndex;
  75.  
  76. @Autowired
  77. private RegionCustomerDao regionCustomerDao;
  78.  
  79. @Override
  80. public String getDescription() {
  81.  
  82. return " Add region customer ";
  83. }
  84.  
  85. @Override
  86. public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  87. log.debug("ini isi input Dto" + inputDto);
  88.  
  89. // Pastikan input benar/lengkap
  90.  
  91. ValidationUtil.valBlankOrNull(inputDto, "tenantLoginId");
  92. log.debug("tenantLoginId");
  93. ValidationUtil.valBlankOrNull(inputDto, "roleLoginId");
  94. log.debug("roleLoginId");
  95. ValidationUtil.valBlankOrNull(inputDto, "userLoginId");
  96. log.debug("userLoginId");
  97. ValidationUtil.valBlankOrNull(inputDto, "datetime");
  98. log.debug("datetime");
  99. ValidationUtil.valBlankOrNull(inputDto, "regionId");
  100. log.debug("regionId");
  101. ValidationUtil.valBlankOrNull(inputDto, "customerId");
  102. log.debug("customerId");
  103.  
  104. Long id = inputDto.getLong("id");
  105. Long tenantLoginId = inputDto.getLong("tenantLoginId");
  106. @SuppressWarnings("unused")
  107. Long roleLoginId = inputDto.getLong("roleLoginId");
  108. @SuppressWarnings("unused")
  109. Long userLoginId = inputDto.getLong("userLoginId");
  110. @SuppressWarnings("unused")
  111. String datetime = inputDto.getString("datetime");
  112. Long regionId = inputDto.getLong("regionId");
  113. Long customerId = inputDto.getLong("customerId");
  114.  
  115.  
  116. // Validation data (business key) is not exists yet in db (add)
  117. Dto paramCheckUniqueDto = new Dto();
  118. paramCheckUniqueDto.put("regionId", regionId);
  119. paramCheckUniqueDto.put("customerId", customerId);
  120.  
  121. Dto resultCheckUniqueDto = isRegionCustomerExistsByIndex
  122. .execute(paramCheckUniqueDto);
  123.  
  124. if (resultCheckUniqueDto.getBoolean("exists")) {
  125. throw new CoreException(
  126. MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS,
  127. resultCheckUniqueDto.getLong("regionCustomerDto.regionId"),
  128. resultCheckUniqueDto.getLong("regionCustomerDto.customerId"));
  129. }
  130.  
  131.  
  132. // prepare data
  133. Dto dtoAdd = new Dto();
  134.  
  135. dtoAdd.put("id", id);
  136. dtoAdd.put("tenantId", tenantLoginId);
  137. dtoAdd.put("roleLoginId", roleLoginId);
  138. dtoAdd.put("regionId", regionId);
  139. dtoAdd.put("userLoginId", userLoginId);
  140. dtoAdd.put("customerId", customerId);
  141. dtoAdd.put("version", inputDto.getLong("version"));
  142.  
  143. log.debug("ini yang di add" + dtoAdd);
  144. // Copy process date and userLoginId
  145. prepareInsertAudit(inputDto, inputDto.getLong("userLoginId"),
  146. inputDto.getString("datetime"));
  147. prepareUpdateAudit(inputDto, inputDto.getLong("userLoginId"),
  148. inputDto.getString("datetime"));
  149.  
  150. inputDto.put("dtoAdd", dtoAdd);
  151.  
  152. return null;
  153. }
  154.  
  155. @Override
  156. public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  157. RegionCustomer entity = GsonUtil.fromDto(inputDto.getDto("dtoAdd"),
  158. RegionCustomer.class);
  159.  
  160. // INSERT to database
  161. regionCustomerDao.persist(entity);
  162.  
  163. return new Dto(entity);
  164. }
  165.  
  166. }
Advertisement
Add Comment
Please, Sign In to add comment