Fanadia_Friska

BT Add

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