Fanadia_Friska

addRegionCustomer

Sep 15th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 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 = Long.class),
  34. @Info(name = "roleLoginId", description = "role login id", type = Long.class),
  35. @Info(name = "userLoginId", description = "userLoginId", type = Long.class),
  36. @Info(name = "datetime", description = "datetime", type = String.class),
  37.  
  38. @Info(name = "regionId", description = "regionId", type = Long.class),
  39. @Info(name = "customerId", description = "customerId", type = Long.class)
  40.  
  41. })
  42. @InfoOut(value = {
  43. @Info(name = "id", description = "id", type = Long.class),
  44. @Info(name = "tenantId", description = "tenantId", type = Long.class),
  45. @Info(name = "regionId", description = "id", type = Long.class),
  46. @Info(name = "customerId", description = "id", type = Long.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 = Long.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, "tenantLoginId");
  88. ValidationUtil.valBlankOrNull(inputDto, "roleLoginId");
  89. ValidationUtil.valBlankOrNull(inputDto, "userLoginId");
  90. ValidationUtil.valBlankOrNull(inputDto, "datetime");
  91.  
  92. ValidationUtil.valBlankOrNull(inputDto, "regionId");
  93. ValidationUtil.valBlankOrNull(inputDto, "customerId");
  94.  
  95. Long tenantLoginId = inputDto.getLong("tenantLoginId");
  96. @SuppressWarnings("unused")
  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. // validasi region customer exists
  104. Dto inputIsRegionCustomerExistsByIdDto = new Dto();
  105. inputIsRegionCustomerExistsByIdDto.put("tenantLoginId", tenantLoginId);
  106. inputIsRegionCustomerExistsByIdDto.put("regionId", regionId);
  107. inputIsRegionCustomerExistsByIdDto.put("customerId", customerId);
  108.  
  109.  
  110. Dto outputIsRegionCustomerExistsByIdDto = isRegionCustomerExistsById
  111. .execute(inputIsRegionCustomerExistsByIdDto);
  112.  
  113. if (outputIsRegionCustomerExistsByIdDto.getBoolean("exists")) {
  114. throw new CoreException(MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS, tenantLoginId);
  115. }
  116.  
  117. // prepare data
  118. Dto dtoAdd = new Dto();
  119.  
  120. dtoAdd.put("tenantLoginId", tenantLoginId);
  121. dtoAdd.put("regionId", regionId);
  122. dtoAdd.put("customerId", customerId);
  123.  
  124. dtoAdd.put("active", inputDto.getString("active"));
  125. dtoAdd.put("version", inputDto.getLong("version"));
  126.  
  127. // Set active datetime if active = Y
  128. if (dtoAdd.getString("active").equals(GeneralConstants.YES)) {
  129. dtoAdd.put("activeDateTime", inputDto.get("datetime"));
  130. dtoAdd.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
  131. } else {
  132. dtoAdd.put("activeDateTime", GeneralConstants.SPACE_VALUE);
  133. dtoAdd.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
  134. }
  135.  
  136. log.debug("ini yang di add" + dtoAdd);
  137. // Prepare audit data - create_datetime, create_user_id,
  138. // update_datetime, update_user_id
  139. prepareInsertAudit(dtoAdd, userLoginId, datetime);
  140. prepareUpdateAudit(dtoAdd, userLoginId, datetime);
  141.  
  142. inputDto.put("dtoAdd", dtoAdd);
  143.  
  144. return null;
  145. }
  146.  
  147. @Override
  148. public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  149. RegionCustomer entity = GsonUtil.fromDto(inputDto.getDto("dtoAdd"), RegionCustomer.class);
  150.  
  151. //INSERT to database
  152. regionCustomerDao.persist(entity);
  153.  
  154. return new Dto(entity);
  155. }
  156.  
  157. }
Advertisement
Add Comment
Please, Sign In to add comment