Advertisement
aadddrr

ValComboValueByCode

Oct 15th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. package org.jleaf.common.bo.combo;
  2.  
  3. import org.jleaf.common.CommonExceptionConstants;
  4. import org.jleaf.common.dao.ComboDao;
  5. import org.jleaf.common.dao.ComboValueDao;
  6. import org.jleaf.common.entity.Combo;
  7. import org.jleaf.common.entity.ComboValue;
  8. import org.jleaf.common.entity.ComboValuePk;
  9. import org.jleaf.core.AbstractBusinessFunction;
  10. import org.jleaf.core.BusinessFunction;
  11. import org.jleaf.core.CoreException;
  12. import org.jleaf.core.Dto;
  13. import org.jleaf.core.annotation.Info;
  14. import org.jleaf.core.annotation.InfoIn;
  15. import org.jleaf.core.annotation.InfoOut;
  16. import org.jleaf.util.ValidationUtil;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19.  
  20.  
  21. /**
  22.  *
  23.  * Validate Combo Value By Code function
  24.  *
  25.  * @author NK
  26.  * @version 1.0
  27.  */
  28.  
  29. @Service
  30. @InfoIn(value={
  31.             @Info(name="comboId",description="combo id",type=String.class),
  32.             @Info(name="code",description="code",type=String.class),
  33.             @Info(name="varName",description="variable name",type=String.class)
  34.          })
  35.  
  36. @InfoOut(value = {})
  37. public class ValComboValueByCode extends AbstractBusinessFunction implements BusinessFunction {
  38.  
  39.     @Autowired
  40.     ComboValueDao comboValueDao;
  41.    
  42.     @Autowired
  43.     ComboDao comboDao;
  44.  
  45.     @Override
  46.     public String getDescription(){
  47.         return "Validate combo value by code and combo id";
  48.     }
  49.  
  50.     @Override
  51.     public Dto execute(Dto inputDto) throws Exception {
  52.        
  53.         Dto outputDto = null;
  54.        
  55.         ValidationUtil.valDtoContainsKey(inputDto, "comboId");
  56.         ValidationUtil.valDtoContainsKey(inputDto, "code");
  57.        
  58.         Combo combo = comboDao.findByPk(inputDto.getString("comboId"));
  59.         if(combo==null) {
  60.             throw new CoreException(CommonExceptionConstants.COMBO_NOT_FOUND,inputDto.getString("comboId"));
  61.         }
  62.        
  63.         ComboValuePk comboValuePk = new ComboValuePk(inputDto.getString("comboId"),
  64.                                                     inputDto.getString("code"));   
  65.         ComboValue comboValue = comboValueDao.findByPk(comboValuePk);
  66.         if(comboValue==null){
  67.             throw new CoreException(CommonExceptionConstants.COMBO_VALUE_NOT_VALID,
  68.                                     inputDto.getString("varName"),
  69.                                     combo.getDescription());
  70.         }
  71.        
  72.         return outputDto;
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement