Fanadia_Friska

AddVehicle.java

Aug 22nd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.61 KB | None | 0 0
  1. package org.jleaf.pos2.bo.vehicle;
  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.VehicleDao;
  16. import org.jleaf.pos2.entity.Vehicle;
  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 Vehicle
  26. *
  27. * @author Henokh Marjie Rivaldy , 26 Juli 2016
  28. */
  29.  
  30. // @formatter:off
  31. @Service
  32. @InfoIn(value = {
  33. @Info(name = "licenseNo", description = "license no", type = String.class, required = true),
  34. @Info(name = "ownerName", description = "owner name", type = String.class, required = true),
  35. @Info(name = "chassisNo", description = "chassis no", type = String.class, required = true),
  36. @Info(name = "engineNo", description = "engine no", type = String.class, required = true),
  37. @Info(name = "vehicleGroupCode",description = "vehicle group code", type = String.class, required = true),
  38. @Info(name = "vehicleTypeCode", description = "vehicle type code", type = String.class, required = true),
  39. @Info(name = "yearMade", description = "year made", type = String.class, required = true),
  40. @Info(name = "customerName", description = "customer name", type = String.class, required = true),
  41. @Info(name = "address1", description = "address1", type = String.class, required = true),
  42. @Info(name = "address2", description = "address2", type = String.class, required = true),
  43. @Info(name = "address3", description = "address3", type = String.class, required = true),
  44. @Info(name = "phone1", description = "phone1", type = String.class, required = true),
  45. @Info(name = "phone2", description = "phone2", type = String.class, required = true),
  46. @Info(name = "active", description = "active", type = String.class),
  47.  
  48. @Info(name = "datetime", description = "date time", type = String.class),
  49. @Info(name = "userLoginId", description = "user login id", type = Long.class),
  50. @Info(name = "userLoginName", description = "user login name", type = String.class),
  51. @Info(name = "roleLoginId", description = "role login id", type = Long.class),
  52. @Info(name = "roleLoginName", description = "role login name", type = String.class)
  53.  
  54. })
  55. @InfoOut(value = {
  56. @Info(name = "vehicleCode", description = "vehicle code", type = String.class),
  57. @Info(name = "licenseNo", description = "license no", type = String.class),
  58. @Info(name = "chassisNo", description = "chassis no", type = String.class),
  59. @Info(name = "engineNo", description = "engine no", type = String.class),
  60. @Info(name = "vehicleGroupCode",description = "vehicle group code", type = String.class), @Info(name = "vehicleTypeCode", description = "vehicle type code", type = String.class),
  61. @Info(name = "yearMade", description = "year made", type = String.class),
  62. @Info(name = "customerName", description = "customer name", type = String.class),
  63. @Info(name = "address1", description = "address1", type = String.class),
  64. @Info(name = "address2", description = "address2", type = String.class),
  65. @Info(name = "address3", description = "address3", type = String.class),
  66. @Info(name = "phone1", description = "phone1", type = String.class),
  67. @Info(name = "phone2", description = "phone2", type = String.class),
  68. @Info(name = "address1", description = "address1", type = String.class),
  69. @Info(name = "active", description = "active", type = String.class),
  70.  
  71. @Info(name = "activeDatetime", description = "active date time", type = String.class),
  72. @Info(name = "nonActiveDatetime",description = "non active datetime",type = String.class),
  73. @Info(name = "createUsername", description = "create username", type = String.class),
  74. @Info(name = "updateDatetime", description = "update datetime", type = String.class),
  75. @Info(name = "updateUsername", description = "update username", type = String.class) })
  76. // @formatter:on
  77. @ErrorList(errorKeys = { PosMasterExceptionConstants.VEHICLE_ALREADY_EXISTS })
  78. public class AddVehicle extends DefaultBusinessTransaction implements
  79. BusinessTransaction {
  80.  
  81. @Autowired
  82. VehicleDao vehicleDao;
  83.  
  84. @Autowired
  85. @Qualifier("findVehicleGroupById")
  86. BusinessFunction findVehicleGroupById;
  87.  
  88. @Autowired
  89. @Qualifier("findVehicleTypeById")
  90. BusinessFunction findVehicleTypeById;
  91.  
  92. @Autowired
  93. @Qualifier("valComboValueByCode")
  94. BusinessFunction valComboValueByCode;
  95.  
  96. @Autowired
  97. @Qualifier("isVehicleExistsById")
  98. BusinessFunction isVehicleExistsById;
  99.  
  100. @Override
  101. public String getDescription() {
  102. return "Add Vehicle";
  103. }
  104.  
  105. @Override
  106. public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  107.  
  108. ValidationUtil.valBlankOrNull(inputDto, "licenseNo");
  109. ValidationUtil.valDtoContainsKey(inputDto, "ownerName");
  110. ValidationUtil.valDtoContainsKey(inputDto, "chassisNo");
  111. ValidationUtil.valDtoContainsKey(inputDto, "engineNo");
  112. ValidationUtil.valBlankOrNull(inputDto, "vehicleGroupCode");
  113. ValidationUtil.valBlankOrNull(inputDto, "vehicleTypeCode");
  114. ValidationUtil.valDtoContainsKey(inputDto, "yearMade");
  115. ValidationUtil.valBlankOrNull(inputDto, "customerName");
  116. ValidationUtil.valDtoContainsKey(inputDto, "address1");
  117. ValidationUtil.valDtoContainsKey(inputDto, "address2");
  118. ValidationUtil.valDtoContainsKey(inputDto, "address3");
  119. ValidationUtil.valDtoContainsKey(inputDto, "phone1");
  120. ValidationUtil.valDtoContainsKey(inputDto, "phone2");
  121. ValidationUtil.valBlankOrNull(inputDto, "active");
  122.  
  123. ValidationUtil.valBlankOrNull(inputDto, "datetime");
  124. ValidationUtil.valBlankOrNull(inputDto, "userLoginId");
  125. ValidationUtil.valBlankOrNull(inputDto, "userLoginName");
  126. ValidationUtil.valBlankOrNull(inputDto, "roleLoginId");
  127. ValidationUtil.valBlankOrNull(inputDto, "roleLoginName");
  128.  
  129. ValidationUtil.valDatetime(inputDto, "datetime");
  130.  
  131. String licenseNo = inputDto.getString("licenseNo").trim().toUpperCase();
  132. String ownerName = inputDto.getString("ownerName");
  133. String chassisNo = inputDto.getString("chassisNo");
  134. String engineNo = inputDto.getString("engineNo");
  135. String vehicleGroupCode = inputDto.getString("vehicleGroupCode");
  136. String vehicleTypeCode = inputDto.getString("vehicleTypeCode");
  137. String yearMade = inputDto.getString("yearMade");
  138. String customerName = inputDto.getString("customerName");
  139. String address1 = inputDto.getString("address1");
  140. String address2 = inputDto.getString("address2");
  141. String address3 = inputDto.getString("address3");
  142. String phone1 = inputDto.getString("phone1");
  143. String phone2 = inputDto.getString("phone2");
  144. String active = inputDto.getString("active");
  145.  
  146. String datetime = inputDto.getString("datetime");
  147. String userLoginId = inputDto.getString("userLoginId");
  148. String userLoginName = inputDto.getString("userLoginName");
  149. String roleLoginId = inputDto.getString("roleLoginId");
  150. String roleLoginName = inputDto.getString("roleLoginName");
  151.  
  152. String vehicleCode = licenseNo
  153. .toUpperCase()
  154. .trim()
  155. .replace(GeneralConstants.SPACE_VALUE,
  156. GeneralConstants.EMPTY_VALUE);
  157.  
  158. // Validasi harus referensi ke master vehivle group
  159. // panggil BF findVehicleGroupById dengan inputan vehicleGroupCode
  160.  
  161. Dto inputDtoForFindVehicleGroupById = new Dto();
  162. inputDtoForFindVehicleGroupById.put("vehicleGroupCode",
  163. vehicleGroupCode);
  164. findVehicleGroupById.execute(inputDtoForFindVehicleGroupById);
  165.  
  166. // Validasi harus referensi ke master vehivle type
  167. // panggil BF findVehicleTypeById dengan inputan vehicleTypeCode
  168.  
  169. Dto inputDtoForFindVehicleTypeById = new Dto();
  170. inputDtoForFindVehicleTypeById.put("vehicleTypeCode", vehicleTypeCode);
  171. findVehicleTypeById.execute(inputDtoForFindVehicleTypeById);
  172.  
  173. // Validation active must be suitable with combo YES NO
  174. Dto paramActiveDto = new Dto();
  175. paramActiveDto.put("comboId", ComboIdConstants.COMBO_YES_NO);
  176. paramActiveDto.put("code", active);
  177. paramActiveDto.put("varName", "active");
  178. valComboValueByCode.execute(paramActiveDto);
  179.  
  180. // Validation data (business key) is not exists yet in db (add)
  181. Dto paramCheckUniqueDto = new Dto();
  182. paramCheckUniqueDto.put("vehicleCode", vehicleCode);
  183. Dto resultCheckUniqueDto = isVehicleExistsById
  184. .execute(paramCheckUniqueDto);
  185.  
  186. if (resultCheckUniqueDto.getBoolean("exists")) {
  187. throw new CoreException(
  188. PosMasterExceptionConstants.VEHICLE_ALREADY_EXISTS,
  189. resultCheckUniqueDto.getString("vehicleDto.vehicleCode"));
  190. }
  191.  
  192. Dto addVehicleDto = new Dto();
  193. addVehicleDto.put("vehicleCode", vehicleCode);
  194. addVehicleDto.put("licenseNo", licenseNo);
  195. addVehicleDto.put("ownerName", ownerName);
  196. addVehicleDto.put("chassisNo", chassisNo);
  197. addVehicleDto.put("engineNo", engineNo);
  198. addVehicleDto.put("vehicleGroupCode", vehicleGroupCode);
  199. addVehicleDto.put("vehicleTypeCode", vehicleTypeCode);
  200. addVehicleDto.put("yearMade", yearMade);
  201. addVehicleDto.put("customerName", customerName);
  202. addVehicleDto.put("address1", address1);
  203. addVehicleDto.put("address2", address2);
  204. addVehicleDto.put("address3", address3);
  205. addVehicleDto.put("phone1", phone1);
  206. addVehicleDto.put("phone2", phone2);
  207.  
  208. addVehicleDto.put("active", active);
  209.  
  210. // Set active datetime if active = Y
  211. if (inputDto.getString("active").equals(GeneralConstants.YES)) {
  212. addVehicleDto.put("activeDateTime", inputDto.get("datetime"));
  213. addVehicleDto
  214. .put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
  215. } else {
  216. addVehicleDto.put("activeDateTime", GeneralConstants.SPACE_VALUE);
  217. addVehicleDto
  218. .put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
  219. }
  220.  
  221. PosUtil.prepareInsertAudit(addVehicleDto,
  222. userLoginName,
  223. datetime);
  224. PosUtil.prepareUpdateAudit(addVehicleDto,
  225. userLoginName,
  226. datetime);
  227.  
  228. inputDto.put("vehicleDto", addVehicleDto);
  229. return null;
  230. }
  231.  
  232. @Override
  233. public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  234.  
  235. Dto vehicleDto = inputDto.getDto("vehicleDto");
  236.  
  237. Vehicle entity = GsonUtil.fromDto(vehicleDto, Vehicle.class);
  238.  
  239. vehicleDao.persist(entity);
  240. return new Dto(entity);
  241. }
  242.  
  243. }
Advertisement
Add Comment
Please, Sign In to add comment