widana

IsTransactionItemExistsByProductCode

Oct 26th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.46 KB | None | 0 0
  1. package org.jleaf.pos2.bo.postransaction;
  2.  
  3. import java.util.List;
  4. import javax.persistence.*;
  5. import org.jleaf.core.AbstractBusinessFunction;
  6. import org.jleaf.core.BusinessFunction;
  7. import org.jleaf.core.Dto;
  8. import org.jleaf.core.annotation.ErrorList;
  9. import org.jleaf.core.annotation.Info;
  10. import org.jleaf.core.annotation.InfoIn;
  11. import org.jleaf.core.annotation.InfoOut;
  12. import org.jleaf.pos2.dao.PosItemDao;
  13. import org.jleaf.pos2.entity.PosItem;
  14. import org.jleaf.util.ValidationUtil;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17.  
  18. /**
  19.  * IsTransactionItemExistsByProductCode
  20.  *
  21.  * @author Widana Nur Azis, Oct 24, 2016
  22.  * @version 1.0
  23.  */
  24.  
  25. //@ formatter:off
  26. @Service
  27. @InfoIn(value = {
  28.         @Info(name = "productCode", description = "productCode", type = String.class, required = true),
  29.         @Info(name = "posId", description = "posId", type = Long.class, required = true)
  30. })
  31. @InfoOut(value = {
  32.         @Info(name = "exists", description = "PosItem exists", type = Boolean.class, required = true),
  33.         @Info(name = "productTransactionItemDto", description = "productTransactionItem Dto", type = Dto.class, required = true)
  34.  
  35. })
  36. @ErrorList(errorKeys = {
  37.  
  38. })
  39.  
  40. //@ formatter:on
  41.  
  42. public class IsTransactionItemExistsByProductCode extends AbstractBusinessFunction implements BusinessFunction {
  43.  
  44.     @Autowired
  45.     PosItemDao posItemDao;
  46.    
  47.     @Override
  48.     public String getDescription() {
  49.         // TODO Auto-generated method stub
  50.         return null;
  51.     }
  52.  
  53.     @SuppressWarnings("unchecked")
  54.     @Override
  55.     public Dto execute(Dto inputDto) throws Exception {
  56.         // TODO Auto-generated method stub
  57.         ValidationUtil.valBlankOrNull(inputDto, "productCode");
  58.         ValidationUtil.valBlankOrNull(inputDto, "posId");
  59.        
  60.         ValidationUtil.valDtoContainsKey(inputDto, "productCode");
  61.         ValidationUtil.valDtoContainsKey(inputDto, "posId");
  62.        
  63.         Dto outputDto;
  64.         boolean exists = false;
  65.        
  66.         Query query = posItemDao.createQuery(" SELECT a FROM org.jleaf.pos2.entity.PosItem a WHERE a.productCode = :productCode AND a.posId = :posId ");
  67.         query.setParameter("productCode", inputDto.getString("productCode"));
  68.         query.setParameter("posId", inputDto.getLong("posId"));
  69.        
  70.         List<PosItem> list = query.getResultList();
  71.        
  72.         outputDto = new Dto();
  73.        
  74.         if(list.size() > 0){
  75.             exists = true;
  76.             outputDto.put("productTransactionItemDto", new Dto(list.get(0)));
  77.         }
  78.         outputDto.put("exists", exists);
  79.        
  80.         return outputDto;
  81.        
  82.     }
  83.  
  84. }
Add Comment
Please, Sign In to add comment