forked from p85126437/datagear
解决某些service获取实体未判空的问题
This commit is contained in:
parent
69af9b638e
commit
f7ffef5d3d
|
@ -139,15 +139,15 @@ public abstract class AbstractMybatisEntityService<ID, T extends Entity<ID>> ext
|
|||
* 注意:加载此实体的私有属性值应通过重写{@linkplain #getByIdFromDB(Object, Map)}来实现,这样它们才会被加入缓存。
|
||||
* </p>
|
||||
* <p>
|
||||
* 此方法的默认实现是:直接返回{@code obj}。
|
||||
* 此方法的默认实现是:直接返回{@code entity}。
|
||||
* </p>
|
||||
*
|
||||
* @see #getById(Object) getById(Object)会在其内部调用此方法
|
||||
*/
|
||||
@Override
|
||||
protected T postProcessGet(T obj)
|
||||
protected T postProcessGet(T entity)
|
||||
{
|
||||
return super.postProcessGet(obj);
|
||||
return super.postProcessGet(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -207,7 +207,7 @@ public abstract class AbstractMybatisEntityService<ID, T extends Entity<ID>> ext
|
|||
*
|
||||
* @param id
|
||||
* @param params
|
||||
* @return
|
||||
* @return 可能返回{@code null}
|
||||
*/
|
||||
protected T getByIdFromDB(ID id, Map<String, Object> params)
|
||||
{
|
||||
|
|
|
@ -90,9 +90,12 @@ public class AuthorizationServiceImpl extends AbstractMybatisEntityService<Strin
|
|||
Authorization authorization = getById(id);
|
||||
|
||||
if (authorization != null)
|
||||
{
|
||||
authorizationUpdated(authorization.getResourceType(), authorization.getResource());
|
||||
return super.deleteById(id);
|
||||
}
|
||||
|
||||
return super.deleteById(id);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -587,6 +587,9 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
|
|||
|
||||
protected void saveDataSetPropertyPOs(DataSetEntity entity)
|
||||
{
|
||||
if (entity == null)
|
||||
return;
|
||||
|
||||
Map<String, Object> delParams = buildParamMap();
|
||||
delParams.put("dataSetId", entity.getId());
|
||||
|
||||
|
@ -608,6 +611,9 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
|
|||
|
||||
protected void saveDataSetParamPOs(DataSetEntity entity)
|
||||
{
|
||||
if (entity == null)
|
||||
return;
|
||||
|
||||
Map<String, Object> delParams = buildParamMap();
|
||||
delParams.put("dataSetId", entity.getId());
|
||||
|
||||
|
|
|
@ -244,6 +244,9 @@ public class HtmlChartWidgetEntityServiceImpl
|
|||
|
||||
protected void saveWidgetDataSetRelations(HtmlChartWidgetEntity entity)
|
||||
{
|
||||
if (entity == null)
|
||||
return;
|
||||
|
||||
Map<String, Object> delParams = buildParamMap();
|
||||
delParams.put("id", entity.getId());
|
||||
|
||||
|
@ -287,6 +290,9 @@ public class HtmlChartWidgetEntityServiceImpl
|
|||
|
||||
protected void setChartDataSetVOs(HtmlChartWidgetEntity entity)
|
||||
{
|
||||
if (entity == null)
|
||||
return;
|
||||
|
||||
Map<String, Object> sqlParams = buildParamMap();
|
||||
sqlParams.put("widgetId", entity.getId());
|
||||
|
||||
|
@ -330,16 +336,19 @@ public class HtmlChartWidgetEntityServiceImpl
|
|||
inflateChartDataSets(entity, forAnalysis);
|
||||
}
|
||||
|
||||
protected void inflateHtmlChartPlugin(HtmlChartWidgetEntity obj, boolean forAnalysis)
|
||||
protected void inflateHtmlChartPlugin(HtmlChartWidgetEntity entity, boolean forAnalysis)
|
||||
{
|
||||
HtmlChartPlugin htmlChartPlugin = obj.getHtmlChartPlugin();
|
||||
if (entity == null)
|
||||
return;
|
||||
|
||||
HtmlChartPlugin htmlChartPlugin = entity.getHtmlChartPlugin();
|
||||
|
||||
if (htmlChartPlugin != null)
|
||||
{
|
||||
HtmlChartPlugin full = getHtmlChartPlugin(htmlChartPlugin.getId());
|
||||
|
||||
if (forAnalysis)
|
||||
obj.setHtmlChartPlugin(full);
|
||||
entity.setHtmlChartPlugin(full);
|
||||
else
|
||||
{
|
||||
if (full != null)
|
||||
|
@ -354,6 +363,9 @@ public class HtmlChartWidgetEntityServiceImpl
|
|||
|
||||
protected void inflateChartDataSets(HtmlChartWidgetEntity entity, boolean forAnalysis)
|
||||
{
|
||||
if (entity == null)
|
||||
return;
|
||||
|
||||
ChartDataSetVO[] chartDataSetVOs = entity.getChartDataSetVOs();
|
||||
|
||||
if (chartDataSetVOs == null || chartDataSetVOs.length == 0)
|
||||
|
@ -438,14 +450,14 @@ public class HtmlChartWidgetEntityServiceImpl
|
|||
return (HtmlChartPlugin) this.chartPluginManager.get(id);
|
||||
}
|
||||
|
||||
protected List<WidgetDataSetRelation> getWidgetDataSetRelations(HtmlChartWidgetEntity obj)
|
||||
protected List<WidgetDataSetRelation> getWidgetDataSetRelations(HtmlChartWidgetEntity entity)
|
||||
{
|
||||
List<WidgetDataSetRelation> list = new ArrayList<>();
|
||||
|
||||
if (obj == null)
|
||||
if (entity == null)
|
||||
return list;
|
||||
|
||||
ChartDataSet[] chartDataSets = obj.getChartDataSets();
|
||||
ChartDataSet[] chartDataSets = entity.getChartDataSets();
|
||||
|
||||
if (chartDataSets == null)
|
||||
return list;
|
||||
|
@ -457,7 +469,8 @@ public class HtmlChartWidgetEntityServiceImpl
|
|||
String propertySignsJson = JsonSupport.generate(chartDataSet.getPropertySigns(), "");
|
||||
String queryJson = JsonSupport.generate(chartDataSet.getQuery(), "");
|
||||
|
||||
WidgetDataSetRelation relation = new WidgetDataSetRelation(obj.getId(), chartDataSet.getDataSet().getId(),
|
||||
WidgetDataSetRelation relation = new WidgetDataSetRelation(entity.getId(),
|
||||
chartDataSet.getDataSet().getId(),
|
||||
i + 1);
|
||||
relation.setPropertySignsJson(propertySignsJson);
|
||||
relation.setAlias(chartDataSet.getAlias());
|
||||
|
|
|
@ -96,7 +96,6 @@ public class SchemaServiceImpl extends AbstractMybatisDataPermissionEntityServic
|
|||
public boolean update(User user, Schema entity) throws PermissionDeniedException
|
||||
{
|
||||
checkSaveUrlPermission(user, entity.getUrl());
|
||||
|
||||
return super.update(user, entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.datagear.management.service.RoleService;
|
|||
import org.datagear.management.service.UserService;
|
||||
import org.datagear.management.util.dialect.MbSqlDialect;
|
||||
import org.datagear.util.IDUtil;
|
||||
import org.datagear.util.StringUtil;
|
||||
import org.mybatis.spring.SqlSessionTemplate;
|
||||
|
||||
/**
|
||||
|
@ -99,6 +100,9 @@ public class UserServiceImpl extends AbstractMybatisEntityService<String, User>
|
|||
|
||||
String id = selectOneMybatis("getIdByName", params);
|
||||
|
||||
if (StringUtil.isEmpty(id))
|
||||
return null;
|
||||
|
||||
return getById(id);
|
||||
}
|
||||
|
||||
|
@ -106,7 +110,9 @@ public class UserServiceImpl extends AbstractMybatisEntityService<String, User>
|
|||
public User getByIdNoPassword(String id)
|
||||
{
|
||||
User user = getById(id);
|
||||
user.clearPassword();
|
||||
|
||||
if (user != null)
|
||||
user.clearPassword();
|
||||
|
||||
return user;
|
||||
}
|
||||
|
@ -185,6 +191,9 @@ public class UserServiceImpl extends AbstractMybatisEntityService<String, User>
|
|||
|
||||
protected void saveUserRoles(User user)
|
||||
{
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
deleteUserRoles(user.getId());
|
||||
|
||||
Set<Role> roles = user.getRoles();
|
||||
|
@ -215,6 +224,9 @@ public class UserServiceImpl extends AbstractMybatisEntityService<String, User>
|
|||
{
|
||||
User user = super.getByIdFromDB(id, params);
|
||||
|
||||
if (user == null)
|
||||
return null;
|
||||
|
||||
Map<String, Object> params1 = buildParamMap();
|
||||
params1.put("userId", user.getId());
|
||||
|
||||
|
@ -240,9 +252,9 @@ public class UserServiceImpl extends AbstractMybatisEntityService<String, User>
|
|||
}
|
||||
|
||||
@Override
|
||||
protected User postProcessGet(User obj)
|
||||
protected User postProcessGet(User entity)
|
||||
{
|
||||
Set<Role> roles = obj.getRoles();
|
||||
Set<Role> roles = entity.getRoles();
|
||||
|
||||
if (roles != null && !roles.isEmpty())
|
||||
{
|
||||
|
@ -254,10 +266,10 @@ public class UserServiceImpl extends AbstractMybatisEntityService<String, User>
|
|||
addIfNonNull(rolesNew, role);
|
||||
}
|
||||
|
||||
obj.setRoles(rolesNew);
|
||||
entity.setRoles(rolesNew);
|
||||
}
|
||||
|
||||
return super.postProcessGet(obj);
|
||||
return super.postProcessGet(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue