Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.common.bo.parameter;
- import java.util.List;
- import javax.persistence.Query;
- import org.jleaf.common.CommonExceptionConstants;
- import org.jleaf.common.dao.SystemConfigDao;
- import org.jleaf.common.entity.SystemConfig;
- import org.jleaf.core.AbstractBusinessFunction;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.CoreException;
- import org.jleaf.core.Dto;
- import org.jleaf.core.annotation.ErrorList;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.util.ValidationUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- /**
- * @author Agik, Oct 30, 2012
- * @version 1.0
- *
- * description : Find system config by specific tenant id and parameter code
- */
- //@formatter:off
- @Service
- @InfoIn(value={@Info(name = "parameterCode", description = "parameter code", type=String.class),
- @Info(name = "tenantId", description = "tenant id", type=Long.class)})
- @InfoOut(value={@Info(name = "id", description = "system config id", type=Long.class),
- @Info(name = "tenantId", description = "tenant id", type=Long.class),
- @Info(name = "parameterId", description = "parameter id", type=Long.class),
- @Info(name = "value", description = "parameter value", type=String.class),
- @Info(name = "active", description = "active", type = String.class),
- @Info(name = "activeDateTime", description = "active date time", type = String.class),
- @Info(name = "nonActiveDateTime", description = "non active date time", type = String.class),
- @Info(name = "createDateTime", description = "create date time", type = String.class),
- @Info(name = "createUserId", description = "create user id", type = Long.class),
- @Info(name = "updateDateTime", description = "update date time", type = String.class),
- @Info(name = "updateUserId", description = "update user id", type = Long.class),
- @Info(name = "version", description = "version", type = Long.class)})
- @ErrorList(errorKeys = {CommonExceptionConstants.SYSTEM_CONFIG_BY_CODE_NOT_FOUND})
- //@formatter:on
- public class FindSystemConfigByParamCode extends AbstractBusinessFunction implements BusinessFunction {
- @Autowired
- SystemConfigDao systemConfigDao;
- @Override
- public String getDescription() {
- return "Find system config by specific tenant id and parameter code";
- }
- @Override
- public Dto execute(Dto inputDto) throws Exception {
- ValidationUtil.valDtoContainsKey(inputDto, "parameterCode");
- ValidationUtil.valDtoContainsKey(inputDto, "tenantId");
- Dto outputDto;
- String parameterCode = inputDto.getString("parameterCode");
- Long tenantId = inputDto.getLong("tenantId");
- Query query = systemConfigDao
- .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 ");
- query.setParameter("tenantId", tenantId);
- query.setParameter("parameterCode", parameterCode);
- @SuppressWarnings("unchecked")
- List<SystemConfig> sysConfigList = query.getResultList();
- if (sysConfigList.size() != 0) {
- outputDto = new Dto(sysConfigList.get(0));
- } else {
- throw new CoreException(CommonExceptionConstants.SYSTEM_CONFIG_BY_CODE_NOT_FOUND, tenantId, parameterCode);
- }
- return outputDto;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement