Advertisement
Guest User

FindUploadParameterByIndex

a guest
Nov 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1. package org.jleaf.erp.master.bo.upload;
  2.  
  3. import javax.persistence.NoResultException;
  4. import javax.persistence.Query;
  5.  
  6. import org.jleaf.core.AbstractBusinessFunction;
  7. import org.jleaf.core.BusinessFunction;
  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.erp.master.dao.ProductDao;
  15. import org.jleaf.util.ValidationUtil;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Service;
  18.  
  19. /**
  20.  * Find Upload Parameter By Index
  21.  * @author Cong, 2017-05-10
  22.  *
  23.  * BF ini digunakan untuk mengambil value dari param upload csv dengan key header id dan key parameter
  24.  * BF ini tidak menghasilkan exception
  25.  * Jika param tidak di temukan, akan mengembalikan empty string
  26.  *
  27.  */
  28.  
  29. @Service
  30. @InfoIn(value = {
  31.     @Info(name = "ulHeaderId", description = "Upload header parameter id", type = Long.class, required = true),
  32.     @Info(name = "key", description = "Key parameter", type = String.class, required = true)
  33. })
  34. @InfoOut(value = {
  35.     @Info(name = "value", description = "result value parameter", type = String.class, required = true)
  36. })
  37. @ErrorList(errorKeys = {
  38. })
  39. public class FindUploadParameterByIndex extends AbstractBusinessFunction implements BusinessFunction{
  40.  
  41.     @Autowired
  42.     ProductDao productDao;
  43.    
  44.     @Override
  45.     public Dto execute(Dto inputDto) throws Exception {
  46.         ValidationUtil.valDtoContainsKey(inputDto, "ulHeaderId");
  47.         ValidationUtil.valDtoContainsKey(inputDto, "key");
  48.  
  49.         Long ulHeaderId = inputDto.getLong("ulHeaderId");
  50.         String key = inputDto.getString("key");
  51.         Dto outputDto = new Dto();
  52.        
  53.         Query query = productDao.createNativeQuery(" SELECT f_get_upload_parameter(:ulHeaderId, :key) as result ");
  54.  
  55.         query.setParameter("ulHeaderId", ulHeaderId);
  56.         query.setParameter("key", key);
  57.        
  58.         Object result = null;
  59.         try {
  60.             result = query.getSingleResult();
  61.         } catch (NoResultException e) {}
  62.        
  63.         if (result!=null) {
  64.             outputDto.putString("value", result.toString());
  65.         } else {
  66.             outputDto.putString("value", GeneralConstants.EMPTY_VALUE);
  67.         }
  68.        
  69.         return outputDto;
  70.     }
  71.  
  72.     @Override
  73.     public String getDescription() {
  74.         return "Find Upload Parameter By Index";
  75.     }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement