Fanadia_Friska

BT ADD ANYAR

Sep 21st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. package org.jleaf.erp.bo.customer.vs.rayon;
  2.  
  3. import org.jleaf.common.ComboIdConstants;
  4. import org.jleaf.core.BusinessFunction;
  5. import org.jleaf.core.BusinessTransaction;
  6. import org.jleaf.core.CoreException;
  7. import org.jleaf.core.DefaultBusinessTransaction;
  8. import org.jleaf.core.Dto;
  9. import org.jleaf.core.GeneralConstants;
  10. import org.jleaf.core.annotation.ErrorList;
  11. import org.jleaf.core.annotation.Info;
  12. import org.jleaf.core.annotation.InfoIn;
  13. import org.jleaf.core.annotation.InfoOut;
  14. import org.jleaf.pos2.PosMasterExceptionConstants;
  15. import org.jleaf.pos2.dao.RegionCustomerDao;
  16. import org.jleaf.pos2.entity.RegionCustomer;
  17. import org.jleaf.pos2.util.PosUtil;
  18. import org.jleaf.util.GsonUtil;
  19. import org.jleaf.util.ValidationUtil;
  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. * Business Transactions: Add Region Customer
  26. *
  27. * @author Nadia , 21 Sept 2016
  28. */
  29.  
  30. // @formatter:off
  31. @Service
  32. @InfoIn(value = {
  33. @Info(name = "tenantLoginId", description = "tenantLoginId", type = Long.class, required = true),
  34. @Info(name = "roleLoginId", description = "roleLoginId", type = Long.class, required = true),
  35. @Info(name = "userLoginId", description = "userLoginId", type = Long.class, required = true),
  36. @Info(name = "datetime", description = "datetime", type = String.class, required = true),
  37.  
  38.  
  39. @Info(name = "regionId", description = "role login id", type = Long.class),
  40. @Info(name = "customerId", description = "role login name", type = Long.class)
  41.  
  42. })
  43. @InfoOut(value = {
  44. @Info(name = "id", description = "id", type = String.class),
  45. @Info(name = "tenantId", description = "tenantId", type = String.class),
  46. @Info(name = "regionId", description = "regionId", type = String.class),
  47. @Info(name = "customerId", description = "customerId", type = String.class),
  48. @Info(name = "createDateTime", description = "createDateTime", type = String.class),
  49. @Info(name = "updateDateTime", description = "updateDateTime", type = String.class),
  50. @Info(name = "createUserId", description = "createUserId", type = String.class),
  51. @Info(name = "updateUserId", description = "updateUserId", type = String.class),
  52. @Info(name = "version", description = "version", type = String.class)
  53. })
  54. // @formatter:on
  55. @ErrorList(errorKeys = { MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS })
  56. public class AddRegionCustomer extends DefaultBusinessTransaction implements
  57. BusinessTransaction {
  58.  
  59. @Autowired
  60. VehicleDao regionCustomerDao;
  61.  
  62. @Autowired
  63. @Qualifier("findRegionCustomerByIndex")
  64. BusinessFunction findRegionCustomerByIndex;
  65.  
  66. @Autowired
  67. @Qualifier("findVehicleTypeById")
  68. BusinessFunction findVehicleTypeById;
  69.  
  70. @Autowired
  71. @Qualifier("valRegionCustomerByIndex")
  72. BusinessFunction valRegionCustomerByIndex;
  73.  
  74. @Autowired
  75. @Qualifier("isRegionCustomerExistsByIndex")
  76. BusinessFunction isRegionCustomerExistsByIndex;
  77.  
  78. @Override
  79. public String getDescription() {
  80. return "Add Region Customer";
  81. }
  82.  
  83. @Override
  84. public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  85.  
  86. ValidationUtil.valBlankOrNull(inputDto, "tenantLoginId");
  87. ValidationUtil.valDtoContainsKey(inputDto, "roleLoginId");
  88. ValidationUtil.valDtoContainsKey(inputDto, "userLoginId");
  89. ValidationUtil.valDtoContainsKey(inputDto, "datetime");
  90. ValidationUtil.valBlankOrNull(inputDto, "regionId");
  91. ValidationUtil.valBlankOrNull(inputDto, "customerId");
  92.  
  93. Long licenseNo = inputDto.getLong("tenantLoginId").trim().toUpperCase();
  94. Long ownerName = inputDto.getLong("roleLoginId");
  95. Long chassisNo = inputDto.getLong("userLoginId");
  96. String engineNo = inputDto.getString("datetime");
  97. Long vehicleGroupCode = inputDto.getLong("regionId");
  98. Long vehicleTypeCode = inputDto.getLong("customerId");
  99.  
  100.  
  101. String id = tenantId
  102. .toUpperCase()
  103. .trim()
  104. .replace(GeneralConstants.SPACE_VALUE,
  105. GeneralConstants.EMPTY_VALUE);
  106.  
  107. // Validasi harus referensi ke master region
  108. // panggil BF findRegionCustomerByIndex dengan inputan regionId
  109.  
  110. Dto inputDtoForFindRegionCustomerByIndex = new Dto();
  111. inputDtoForFindRegionCustomerByIndex.put("regionId",
  112. regionId);
  113. findRegionCustomerByIndex.execute(inputDtoForFindRegionCustomerByIndex);
  114.  
  115. // Validasi harus referensi ke master partner
  116. // panggil BF findRegionCustomerById dengan inputan regionId
  117.  
  118. Dto inputDtoForFindRegionCustomerById = new Dto();
  119. inputDtoForFindRegionCustomerById.put("regionId", regionId);
  120. findRegionCustomerById.execute(inputDtoForFindVehicleTypeById);
  121.  
  122. // Validation active must be suitable with combo YES NO
  123. Dto paramActiveDto = new Dto();
  124. paramActiveDto.put("comboId", ComboIdConstants.COMBO_YES_NO);
  125. paramActiveDto.put("code", active);
  126. paramActiveDto.put("varName", "active");
  127. valComboValueByCode.execute(paramActiveDto);
  128.  
  129. // Validation data (business key) is not exists yet in db (add)
  130. Dto paramCheckUniqueDto = new Dto();
  131. paramCheckUniqueDto.put("regionId", regionId);
  132. paramCheckUniqueDto.put("customerId", customerId);
  133.  
  134. Dto resultCheckUniqueDto = isRegionCustomerByIndex
  135. .execute(paramCheckUniqueDto);
  136.  
  137. if (resultCheckUniqueDto.getBoolean("exists")) {
  138. throw new CoreException(
  139. MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS,
  140. resultCheckUniqueDto.getString("regionCustomerDto.regionId"),
  141. resultCheckUniqueDto.getString("regionCustomerDto.customerId"));
  142. }
  143.  
  144. Dto addRegionCustomerDto = new Dto();
  145. addVehicleDto.put("id", id);
  146. addVehicleDto.put("tenantId", tenantId);
  147. addVehicleDto.put("regionId", regionId);
  148. addVehicleDto.put("customerId", customerId);
  149. addVehicleDto.put("createDatetime", createDatetime);
  150. addVehicleDto.put("updateDatetime", updateDatetime);
  151. addVehicleDto.put("createUserId", createUserId);
  152. addVehicleDto.put("updateUserId", updateUserId);
  153. addVehicleDto.put("version", version);
  154.  
  155. // Set active datetime if active = Y
  156. if (inputDto.getString("active").equals(GeneralConstants.YES)) {
  157. addVehicleDto.put("activeDateTime", inputDto.get("datetime"));
  158. addVehicleDto
  159. .put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
  160. } else {
  161. addVehicleDto.put("activeDateTime", GeneralConstants.SPACE_VALUE);
  162. addVehicleDto
  163. .put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
  164. }
  165.  
  166. PosUtil.prepareInsertAudit(addRegionCustomerDto,
  167. userLoginName,
  168. datetime);
  169. PosUtil.prepareUpdateAudit(addRegionCustomerDto,
  170. userLoginName,
  171. datetime);
  172.  
  173. inputDto.put("regionCustomerDto", regionCustomerDto);
  174. return null;
  175. }
  176.  
  177. @Override
  178. public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  179.  
  180. Dto regionCustomerDto = inputDto.getDto("regionCustomerDto");
  181.  
  182. RegionCustomer entity = GsonUtil.fromDto(regionCustomerDto, RegionCustomer.class);
  183.  
  184. regionCustomerDao.persist(entity);
  185. return new Dto(entity);
  186. }
  187.  
  188. }
Add Comment
Please, Sign In to add comment