Fanadia_Friska

add nadia

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