Advertisement
aadddrr

Untitled

Aug 10th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.39 KB | None | 0 0
  1. package org.jleaf.common.bo.parameter;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.Query;
  6.  
  7. import org.jleaf.common.CommonExceptionConstants;
  8. import org.jleaf.common.dao.SystemConfigDao;
  9. import org.jleaf.common.entity.SystemConfig;
  10. import org.jleaf.core.AbstractBusinessFunction;
  11. import org.jleaf.core.BusinessFunction;
  12. import org.jleaf.core.CoreException;
  13. import org.jleaf.core.Dto;
  14. import org.jleaf.core.annotation.ErrorList;
  15. import org.jleaf.core.annotation.Info;
  16. import org.jleaf.core.annotation.InfoIn;
  17. import org.jleaf.core.annotation.InfoOut;
  18. import org.jleaf.util.ValidationUtil;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21.  
  22. /**
  23.  * @author Agik, Oct 30, 2012
  24.  * @version 1.0
  25.  *
  26.  * description : Find system config by specific tenant id and parameter code
  27.  */
  28.  
  29. //@formatter:off
  30. @Service
  31. @InfoIn(value={@Info(name = "parameterCode", description = "parameter code", type=String.class),
  32.         @Info(name = "tenantId", description = "tenant id", type=Long.class)})
  33. @InfoOut(value={@Info(name = "id", description = "system config id", type=Long.class),
  34.         @Info(name = "tenantId", description = "tenant id", type=Long.class),
  35.         @Info(name = "parameterId", description = "parameter id", type=Long.class),
  36.         @Info(name = "value", description = "parameter value", type=String.class),     
  37.         @Info(name = "active", description = "active", type = String.class),
  38.         @Info(name = "activeDateTime", description = "active date time", type = String.class),
  39.         @Info(name = "nonActiveDateTime", description = "non active date time", type = String.class),
  40.         @Info(name = "createDateTime", description = "create date time", type = String.class),
  41.         @Info(name = "createUserId", description = "create user id", type = Long.class),
  42.         @Info(name = "updateDateTime", description = "update date time", type = String.class),
  43.         @Info(name = "updateUserId", description = "update user id", type = Long.class),
  44.         @Info(name = "version", description = "version", type = Long.class)})
  45. @ErrorList(errorKeys = {CommonExceptionConstants.SYSTEM_CONFIG_BY_CODE_NOT_FOUND})
  46. //@formatter:on
  47. public class FindSystemConfigByParamCode extends AbstractBusinessFunction implements BusinessFunction {
  48.  
  49.     @Autowired
  50.     SystemConfigDao systemConfigDao;
  51.  
  52.     @Override
  53.     public String getDescription() {
  54.         return "Find system config by specific tenant id and parameter code";
  55.     }
  56.  
  57.     @Override
  58.     public Dto execute(Dto inputDto) throws Exception {
  59.         ValidationUtil.valDtoContainsKey(inputDto, "parameterCode");
  60.         ValidationUtil.valDtoContainsKey(inputDto, "tenantId");
  61.  
  62.         Dto outputDto;
  63.  
  64.         String parameterCode = inputDto.getString("parameterCode");
  65.         Long tenantId = inputDto.getLong("tenantId");
  66.  
  67.         Query query = systemConfigDao
  68.                 .createQuery("SELECT f FROM org.jleaf.common.entity.Parameter e, org.jleaf.common.entity.SystemConfig f WHERE e.code = :parameterCode AND e.id = f.parameterId AND f.tenantId = :tenantId ");
  69.         query.setParameter("tenantId", tenantId);
  70.         query.setParameter("parameterCode", parameterCode);
  71.  
  72.         @SuppressWarnings("unchecked")
  73.         List<SystemConfig> sysConfigList = query.getResultList();
  74.         if (sysConfigList.size() != 0) {
  75.             outputDto = new Dto(sysConfigList.get(0));
  76.         } else {
  77.             throw new CoreException(CommonExceptionConstants.SYSTEM_CONFIG_BY_CODE_NOT_FOUND, tenantId, parameterCode);
  78.         }
  79.  
  80.         return outputDto;
  81.     }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement