Fanadia_Friska

ini BT Add

Sep 20th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 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.  
  32. @Service
  33. @InfoIn(value = {
  34. @Info(name = "tenantLoginId", description = "tenant login id", type = Long.class),
  35. @Info(name = "roleLoginId", description = "role login id", type = Long.class),
  36. @Info(name = "userLoginId", description = "user Id", type = Long.class),
  37. @Info(name = "datetime", description = "datetime", type = String.class),
  38.  
  39. @Info(name = "regionId", description = "region Id", type = Long.class),
  40. @Info(name = "customerId", description = "customer Id", type = Long.class)
  41.  
  42. })
  43.  
  44.  
  45. @InfoOut(value={
  46. @Info(name = "regionCustomerList", description = "region customer list("
  47. + " id, tenantId, regionId, customerId,"
  48. + " createDatetime, updateDatetime, createUserId, "
  49. + " updateUserId, version ))")
  50. })
  51.  
  52.  
  53. //@InfoOut(value = {
  54. // @Info(name = "id", description = "id", type = Long.class),
  55. // @Info(name = "tenantId", description = "tenantId", type = Long.class),
  56. // @Info(name = "regionId", description = "id", type = Long.class),
  57. // @Info(name = "customerId", description = "id", type =Long.class),
  58. // @Info(name = "createDateTime", description = "create date time", type = String.class),
  59. // @Info(name = "updateDateTime", description = "update date time", type = String.class),
  60. // @Info(name = "createUserId", description = "create user id", type = Long.class),
  61. // @Info(name = "updateUserId", description = "update user id", type = Long.class),
  62. // @Info(name = "version", description = "version", type = String.class)
  63. //
  64. //})
  65. @ErrorList(errorKeys = { MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS })
  66. public class AddRegionCustomer extends DefaultBusinessTransaction implements
  67. BusinessTransaction {
  68. private static final Logger log = LoggerFactory.getLogger(AddRegionCustomer.class);
  69.  
  70. @Autowired
  71. @Qualifier("findRegionCustomerByIndex")
  72. private BusinessFunction findRegionCustomerByIndex;
  73.  
  74. @Autowired
  75. @Qualifier("isRegionCustomerExistsById")
  76. BusinessFunction isRegionCustomerExistsById;
  77.  
  78. @Autowired
  79. private RegionCustomerDao regionCustomerDao;
  80.  
  81. @Override
  82. public String getDescription() {
  83.  
  84. return " Add region customer ";
  85. }
  86.  
  87. @Override
  88. public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  89. log.debug("ini isi input Dto" + inputDto);
  90.  
  91. // Pastikan input benar/lengkap
  92. ValidationUtil.valBlankOrNull(inputDto, "tenantLoginId");
  93. log.debug("tenantLoginId");
  94. ValidationUtil.valBlankOrNull(inputDto, "roleLoginId");
  95. log.debug("roleLoginId");
  96. ValidationUtil.valBlankOrNull(inputDto, "userLoginId");
  97. log.debug("userLoginId");
  98. ValidationUtil.valBlankOrNull(inputDto, "datetime");
  99. log.debug("datetime");
  100. ValidationUtil.valBlankOrNull(inputDto, "regionId");
  101. log.debug("regionId");
  102. ValidationUtil.valBlankOrNull(inputDto, "customerId");
  103. log.debug("customerId");
  104.  
  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. // validasi data (business key) is not exists yet in db (add)
  116. Dto inputFindRegionCustomerByIndexDto = new Dto();
  117. inputFindRegionCustomerByIndexDto.put("regionId", inputDto.getLong("regionId"));
  118. inputFindRegionCustomerByIndexDto.put("customerId", inputDto.getLong("customerId"));
  119. Dto outputFindRegionCustomerByIndexDto =findRegionCustomerByIndex.execute(inputFindRegionCustomerByIndexDto);
  120.  
  121. if (outputFindRegionCustomerByIndexDto.getBoolean("exists")){
  122. throw new CoreException(MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS,
  123. outputFindRegionCustomerByIndexDto.getString("regionCustomerDto.regionId"),
  124. outputFindRegionCustomerByIndexDto.get("regionCustomerDto.customerId"));
  125. }
  126. // prepare data
  127. Dto dtoAdd = new Dto();
  128.  
  129. dtoAdd.put("tenantId", tenantLoginId);
  130. dtoAdd.put("roleLoginId", roleLoginId);
  131. dtoAdd.put("regionId", regionId);
  132. dtoAdd.put("userLoginId", userLoginId);
  133. dtoAdd.put("customerId", customerId);
  134. dtoAdd.put("version", inputDto.getLong("version"));
  135.  
  136. log.debug("ini yang di add" + dtoAdd);
  137. // Copy process date and userLoginId
  138. prepareInsertAudit(inputDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
  139. prepareUpdateAudit(inputDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
  140.  
  141. inputDto.put("dtoAdd", dtoAdd);
  142.  
  143. return null;
  144. }
  145.  
  146. @Override
  147. public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  148. RegionCustomer entity = GsonUtil.fromDto(inputDto.getDto("dtoAdd"), RegionCustomer.class);
  149.  
  150. //INSERT to database
  151. regionCustomerDao.persist(entity);
  152.  
  153. return new Dto(entity);
  154. }
  155.  
  156. }
Advertisement
Add Comment
Please, Sign In to add comment