Fanadia_Friska

find dari generate nadia

Sep 20th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. package org.jleaf.erp.master.bo.customervsrayon;
  2.  
  3. import java.util.List;
  4. import javax.persistence.Query;
  5.  
  6. import org.jleaf.core.AbstractBusinessFunction;
  7. import org.jleaf.core.BusinessFunction;
  8. import org.jleaf.core.CoreException;
  9. import org.jleaf.core.Dto;
  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.util.ValidationUtil;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17.  
  18. import org.jleaf.erp.master.entity.RegionCustomer;
  19. import org.jleaf.erp.master.dao.RegionCustomerDao;
  20. import org.jleaf.erp.master.MasterExceptionConstantsForDlg;
  21.  
  22.  
  23. /**
  24. * Find RegionCustomer by index
  25. * @author Nadia, Sep 19, 2016
  26. * @version 1.0
  27. */
  28.  
  29. @Service
  30. @InfoIn(value = {
  31. @Info(name = "regionId", description = "Region id", type = Long.class, required = true),
  32. @Info(name = "customerId", description = "Customer id", type = Long.class, required = true)
  33. })
  34. @InfoOut(value = {
  35. @Info(name = "regionCustomerId", description = "Region customer id", type = Long.class, required = true),
  36. @Info(name = "tenantId", description = "Tenant id", type = Long.class, required = true),
  37. @Info(name = "regionId", description = "Region id", type = Long.class, required = true),
  38. @Info(name = "customerId", description = "Customer id", type = Long.class, required = true),
  39. @Info(name = "active", description = "Active", type = String.class, required = true),
  40. @Info(name = "activeDateTime", description = "Active date time", type = String.class, required = true),
  41. @Info(name = "nonActiveDateTime", description = "Non active date time", type = String.class, required = true),
  42. @Info(name = "createUserId", description = "Create user id", type = Long.class, required = true),
  43. @Info(name = "createDateTime", description = "Create date time", type = String.class, required = true),
  44. @Info(name = "updateUserId", description = "Update user id", type = Long.class, required = true),
  45. @Info(name = "updateDateTime", description = "Update date time", type = String.class, required = true),
  46. @Info(name = "version", description = "Version", type = Long.class, required = true)
  47. })
  48. @ErrorList(errorKeys = {
  49. MasterExceptionConstantsForDlg.REGION_CUSTOMER_NOT_FOUND
  50. })
  51. public class FindRegionCustomerByIndex extends AbstractBusinessFunction implements BusinessFunction {
  52.  
  53. @Autowired
  54. private RegionCustomerDao regionCustomerDao;
  55.  
  56. @SuppressWarnings("unchecked")
  57. @Override
  58. public Dto execute(Dto inputDto) throws Exception {
  59. ValidationUtil.valDtoContainsKey(inputDto, "regionId");
  60. ValidationUtil.valDtoContainsKey(inputDto, "customerId");
  61.  
  62.  
  63. Dto outputDto = null;
  64.  
  65. Long regionId = inputDto.getLong("regionId");
  66. Long customerId = inputDto.getLong("customerId");
  67.  
  68.  
  69. Query query = regionCustomerDao
  70. .createQuery("SELECT e FROM "+RegionCustomer.ENTITY_NAME+" e WHERE e.regionId = :regionId AND e.customerId = :customerId");
  71.  
  72. query.setParameter("regionId", regionId);
  73. query.setParameter("customerId", customerId);
  74.  
  75.  
  76. List<RegionCustomer> regionCustomerList = query.getResultList();
  77. if (regionCustomerList.size() != 0) {
  78. outputDto = new Dto(regionCustomerList.get(0));
  79. } else {
  80. throw new CoreException(MasterExceptionConstantsForDlg.REGION_CUSTOMER_NOT_FOUND,regionId,customerId);
  81. }
  82.  
  83. return outputDto;
  84. }
  85.  
  86. @Override
  87. public String getDescription() {
  88. return "Find RegionCustomer by index ";
  89. }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment