Fanadia_Friska

nitip add region customer

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