提交 53400b61 编写于 作者: 程剑

Merge branch '合并内容管理权限修改' into 'develop'

合并内容管理权限修改

See merge request o2oa/o2oa!1315
......@@ -54,6 +54,19 @@ public class AppInfoFactory extends AbstractFactory {
return em.createQuery(cq).getResultList();
}
public List<String> listByAppType(String appType) throws Exception {
EntityManager em = this.entityManagerContainer().get(AppInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<AppInfo> root = cq.from(AppInfo.class);
cq.select(root.get(AppInfo_.id));
if (StringUtils.isNotEmpty(appType) && !"全部".equals(appType) && !"all".equalsIgnoreCase(appType)) {
Predicate p = cb.equal(root.get(AppInfo_.appType), appType);
return em.createQuery(cq.where(p)).getResultList();
}
return em.createQuery(cq).getResultList();
}
public List<AppInfo> listAll( String appType, String documentType) throws Exception {
EntityManager em = this.entityManagerContainer().get(AppInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
......@@ -132,6 +145,39 @@ public class AppInfoFactory extends AbstractFactory {
return em.createQuery(cq.where(p)).getResultList().stream().distinct().collect(Collectors.toList());
}
public List<String> listPeopleViewAppInfoIds(String personName, List<String> unitNames, List<String> groupNames, String appType, Boolean isManager) throws Exception {
if(BooleanUtils.isTrue(isManager)){
return listByAppType(appType);
}
EntityManager em = this.entityManagerContainer().get(AppInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<AppInfo> root = cq.from(AppInfo.class);
cq.select(root.get(AppInfo_.id));
Predicate p = cb.disjunction();
if (StringUtils.isNotEmpty(appType) && !"全部".equals(appType) && !"all".equalsIgnoreCase(appType)) {
p = cb.or(p, cb.and(cb.isTrue(root.get(AppInfo_.allPeopleView)), cb.equal(root.get(AppInfo_.appType), appType)));
}else{
p = cb.or(p, cb.isTrue(root.get(AppInfo_.allPeopleView)));
}
if (StringUtils.isNotEmpty(personName)) {
p = cb.or(p, cb.isMember(personName, root.get(AppInfo_.viewablePersonList)));
p = cb.or(p, cb.isMember(personName, root.get(AppInfo_.publishablePersonList)));
p = cb.or(p, cb.isMember(personName, root.get(AppInfo_.manageablePersonList)));
}
if(ListTools.isNotEmpty(unitNames)){
p = cb.or(p, root.get(AppInfo_.viewableUnitList).in(unitNames));
p = cb.or(p, root.get(AppInfo_.publishableUnitList).in(unitNames));
p = cb.or(p, root.get(AppInfo_.manageableUnitList).in(unitNames));
}
if(ListTools.isNotEmpty(groupNames)){
p = cb.or(p, root.get(AppInfo_.viewableGroupList).in(unitNames));
p = cb.or(p, root.get(AppInfo_.publishableGroupList).in(groupNames));
p = cb.or(p, root.get(AppInfo_.manageableGroupList).in(groupNames));
}
return em.createQuery(cq.where(p)).getResultList().stream().distinct().collect(Collectors.toList());
}
/**
* 查询所有未设置可见权限的AppInfo的ID列表( with List copy ) 全员可发布的栏目也包含在内:判断allPeopleView or
* allPeoplePublish
......
......@@ -70,7 +70,37 @@ public class CategoryInfoFactory extends ElementFactory {
Root<CategoryInfo> root = cq.from( CategoryInfo.class );
Predicate p = cb.equal(root.get( CategoryInfo_.appId ), appId );
cq.select(root.get( CategoryInfo_.id));
return em.createQuery( cq.where(p) ).setMaxResults(1000).getResultList();
return em.createQuery( cq.where(p) ).getResultList();
}
public List<String> listPeopleViewIds(String personName, List<String> unitNames, List<String> groupNames, String appId, Boolean isManager) throws Exception {
if(BooleanUtils.isTrue(isManager)){
return listByAppId(appId);
}
EntityManager em = this.entityManagerContainer().get(CategoryInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<CategoryInfo> root = cq.from(CategoryInfo.class);
cq.select(root.get(CategoryInfo_.id));
Predicate query = cb.equal(root.get(CategoryInfo_.appId), appId);
Predicate p = cb.isTrue(root.get(CategoryInfo_.allPeopleView));
if (StringUtils.isNotEmpty(personName)) {
p = cb.or(p, cb.isMember(personName, root.get(CategoryInfo_.viewablePersonList)));
p = cb.or(p, cb.isMember(personName, root.get(CategoryInfo_.publishablePersonList)));
p = cb.or(p, cb.isMember(personName, root.get(CategoryInfo_.manageablePersonList)));
}
if(ListTools.isNotEmpty(unitNames)){
p = cb.or(p, root.get(CategoryInfo_.viewableUnitList).in(unitNames));
p = cb.or(p, root.get(CategoryInfo_.publishableUnitList).in(unitNames));
p = cb.or(p, root.get(CategoryInfo_.manageableUnitList).in(unitNames));
}
if(ListTools.isNotEmpty(groupNames)){
p = cb.or(p, root.get(CategoryInfo_.viewableGroupList).in(unitNames));
p = cb.or(p, root.get(CategoryInfo_.publishableGroupList).in(groupNames));
p = cb.or(p, root.get(CategoryInfo_.manageableGroupList).in(groupNames));
}
query = cb.and(query, p);
return em.createQuery(cq.where(query)).getResultList().stream().distinct().collect(Collectors.toList());
}
public List<String> listByAppIds( List<String> appIds, Boolean hasProcess) throws Exception {
......
package com.x.cms.assemble.control.factory;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Tuple;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import javax.persistence.criteria.Subquery;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.cms.core.entity.enums.DocumentStatus;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
......@@ -28,13 +8,20 @@ import com.x.base.core.project.tools.DateTools;
import com.x.base.core.project.tools.ListTools;
import com.x.cms.assemble.control.AbstractFactory;
import com.x.cms.assemble.control.Business;
import com.x.cms.core.entity.CmsBatchOperation_;
import com.x.cms.core.entity.Document;
import com.x.cms.core.entity.Document_;
import com.x.cms.core.entity.Review;
import com.x.cms.core.entity.Review_;
import com.x.cms.core.entity.*;
import com.x.cms.core.entity.enums.DocumentStatus;
import com.x.cms.core.express.tools.CriteriaBuilderTools;
import com.x.cms.core.express.tools.filter.QueryFilter;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.EntityManager;
import javax.persistence.Tuple;
import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 文档信息基础功能服务类
*
......@@ -658,6 +645,16 @@ public class DocumentFactory extends AbstractFactory {
return em.createQuery(cq.where(p)).setMaxResults(999).getResultList();
}
public List<String> listApp() throws Exception {
EntityManager em = this.entityManagerContainer().get( Document.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<Document> root = cq.from( Document.class );
Predicate p = cb.equal(root.get(Document_.docStatus), DocumentStatus.PUBLISHED.getValue());
cq.select(root.get( Document_.appId)).distinct(true).where(p);
return em.createQuery( cq ).getResultList();
}
public static class DocumentWo extends Document{
static WrapCopier<Document, DocumentWo> copier = WrapCopierFactory.wo(Document.class, DocumentWo.class,
......
......@@ -46,6 +46,17 @@ public class ReviewFactory extends AbstractFactory {
return em.createQuery(cq).getSingleResult();
}
public List<String> listApp( String person ) throws Exception {
EntityManager em = this.entityManagerContainer().get( Review.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<Review> root = cq.from( Review.class );
Predicate p = cb.equal(root.get( Review_.permissionObj ), person );
p = cb.or(p, cb.equal(root.get( Review_.permissionObj ), "*" ));
cq.select(root.get( Review_.appId)).distinct(true).where(p);
return em.createQuery( cq ).getResultList();
}
public List<String> listByAppId( String appId, Integer maxCount ) throws Exception {
if( maxCount == null ) {
maxCount = 1000;
......@@ -79,7 +90,12 @@ public class ReviewFactory extends AbstractFactory {
Root<Review> root = cq.from( Review.class );
Predicate p = cb.equal(root.get( Review_.docId ), docId );
cq.select(root.get( Review_.id)).where(p);
return em.createQuery( cq ).setMaxResults(maxCount).getResultList();
if(maxCount != null && maxCount > 0){
return em.createQuery( cq ).setMaxResults(maxCount).getResultList();
}else{
return em.createQuery( cq ).getResultList();
}
}
public List<String> listByDocumentAndPerson(String docId, String person) throws Exception {
......@@ -172,12 +188,6 @@ public class ReviewFactory extends AbstractFactory {
Predicate p = CriteriaBuilderTools.composePredicateWithQueryFilter( Review_.class, cb, p_permission, root, queryFilter );
List<Order> orders = new ArrayList<>();
if( !Review.isTop_FIELDNAME.equals( orderField )) {
Order isTopOrder = CriteriaBuilderTools.getOrder( cb, root, Review_.class, Review.isTop_FIELDNAME, "desc" );
if( isTopOrder != null ){
orders.add( isTopOrder );
}
}
Order orderWithField = CriteriaBuilderTools.getOrder( cb, root, Review_.class, orderField, orderType );
if( orderWithField != null ){
orders.add( orderWithField );
......
package com.x.cms.assemble.control.jaxrs.appinfo;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.cache.Cache;
import com.x.base.core.project.cache.CacheManager;
......@@ -15,29 +11,31 @@ import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.SortTools;
import com.x.cms.assemble.control.Business;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @author sword
*/
public class ActionListAllAppType extends BaseAction {
private static Logger logger = LoggerFactory.getLogger( ActionListAllAppType.class );
@SuppressWarnings("unchecked")
protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson ) throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = null;
List<String> appTypes = null;
Boolean check = true;
List<Wo> wos = new ArrayList<>();
String personName = effectivePerson.getDistinguishedName();
Boolean isAnonymous = effectivePerson.isAnonymous();
Boolean isManager = false;
try {
isManager = userManagerService.isManager( effectivePerson );
} catch (Exception e) {
check = false;
Exception exception = new ExceptionAppInfoProcess(e, "系统在检查用户是否是平台管理员时发生异常。Name:" + personName);
result.error(exception);
logger.error(e, effectivePerson, request, null);
}
Business business = new Business(null);
Boolean isManager = business.isManager( effectivePerson );
Cache.CacheKey cacheKey = new Cache.CacheKey( this.getClass(), personName, isAnonymous, isManager );
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
......@@ -45,81 +43,66 @@ public class ActionListAllAppType extends BaseAction {
if (optional.isPresent()) {
result.setData((List<Wo>)optional.get());
} else {
wos = new ArrayList<>();
try {
appTypes = appInfoServiceAdv.listAllAppType();
} catch (Exception e) {
check = false;
Exception exception = new ExceptionAppInfoProcess( e, "查询所有应用栏目信息对象时发生异常" );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
if( check ){
//查询每个类别的应用ID列表,查询出ID列表后,根据ID列表查询用户可访问的栏目对象
List<String> appIdsForType = null;
if(ListTools.isNotEmpty( appTypes ) ){
for( String appType : appTypes ) {
if( !"未分类".equals( appType )) {
appIdsForType = appInfoServiceAdv.listAppIdsWithAppType( appType );
if( !isManager && ListTools.isNotEmpty( appIdsForType ) ){
List<String> unitNames = userManagerService.listUnitNamesWithPerson( personName );
List<String> groupNames = userManagerService.listGroupNamesByPerson( personName );
appIdsForType = permissionQueryService.listViewableAppIdByPerson( personName, isAnonymous, unitNames, groupNames, appIdsForType, null, null, appType, 99 );
}
if( appIdsForType == null ){
appIdsForType = new ArrayList<>();
}
if( appIdsForType.size() > 0 ) {
wos.add( new Wo( appType, Long.parseLong( appIdsForType.size() + "") ));
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
business = new Business(emc);
List<String> unitNames = null;
List<String> groupNames = null;
if(!isManager && !isAnonymous) {
unitNames = userManagerService.listUnitNamesWithPerson(personName);
groupNames = userManagerService.listGroupNamesByPerson(personName);
}
List<String> appIds = business.getAppInfoFactory().listPeopleViewAppInfoIds(personName, unitNames, groupNames, "全部", isManager);
if(ListTools.isNotEmpty(appIds)){
final String noneType = "未分类";
List<BaseAction.Wo> apps = emc.fetch(appIds, BaseAction.Wo.copier3);
apps.stream().forEach(app -> {
if(StringUtils.isBlank(app.getAppType())){
app.setAppType(noneType);
}
});
Map<String, List<BaseAction.Wo>> appMap = apps.stream().collect(Collectors.groupingBy(BaseAction.Wo::getAppType));
List<String> appTypes = new ArrayList<>(appMap.keySet());
SortTools.asc(appTypes);
for(String appType : appTypes){
if(!appType.equals(noneType)){
wos.add( new Wo( appType, appMap.get(appType).size() ));
}
}
if(appTypes.contains(noneType)){
wos.add( new Wo( noneType, appMap.get(noneType).size() ));
}
}
//查询所有的未分类的并且有权限查看的栏目列表
appIdsForType = appInfoServiceAdv.listAppIdsWithOutAppType();
if( !isManager && ListTools.isNotEmpty( appIdsForType ) ){
List<String> unitNames = userManagerService.listUnitNamesWithPerson( personName );
List<String> groupNames = userManagerService.listGroupNamesByPerson( personName );
appIdsForType = permissionQueryService.listViewableAppIdByPerson( personName, isAnonymous, unitNames, groupNames, appIdsForType, null, null, null, 99 );
}
if( appIdsForType == null ){
appIdsForType = new ArrayList<>();
}
if( appIdsForType.size() > 0 ) {
wos.add( new Wo( "未分类", Long.parseLong( appIdsForType.size() + "") ));
}
CacheManager.put(cacheCategory, cacheKey, wos);
result.setData( wos );
CacheManager.put(cacheCategory, cacheKey, wos);
}
}
return result;
}
public static class Wo extends GsonPropertyObject {
@FieldDescribe("栏目类别名称")
private String appType;
@FieldDescribe("栏目数量")
private Long count;
public Wo( String _appType, Long _count ) {
private Integer count;
public Wo( String _appType, Integer _count ) {
this.appType = _appType;
this.count = _count;
}
public String getAppType() {
return appType;
}
public void setAppType(String appType) {
this.appType = appType;
}
public Long getCount() {
public Integer getCount() {
return count;
}
public void setCount(Long count) {
public void setCount(Integer count) {
this.count = count;
}
}
}
\ No newline at end of file
}
package com.x.cms.assemble.control.jaxrs.appinfo;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.cache.Cache;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.SortTools;
import com.x.cms.assemble.control.Business;
import com.x.cms.core.entity.AppInfo;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* 列示有权限看到文档的应用
* @author sword
*/
public class ActionListHasDocument extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(ActionListHasDocument.class);
protected ActionResult<List<Wo>> execute(HttpServletRequest request, EffectivePerson effectivePerson)
throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
String personName = effectivePerson.getDistinguishedName();
Cache.CacheKey cacheKey = new Cache.CacheKey( this.getClass(), personName);
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((List<Wo>)optional.get());
} else {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
Boolean isManager = business.isManager( effectivePerson );
List<String> appIds;
List<String> unitNames = null;
List<String> groupNames = null;
if(isManager){
appIds = business.getDocumentFactory().listApp();
}else{
appIds = business.reviewFactory().listApp(personName);
unitNames = userManagerService.listUnitNamesWithPerson(personName);
groupNames = userManagerService.listGroupNamesByPerson(personName);
}
if(ListTools.isNotEmpty(appIds)){
List<AppInfo> apps = emc.list(AppInfo.class, appIds);
for(AppInfo appInfo : apps){
Wo wo = Wo.copier2.copy(appInfo);
try {
wo.setConfig(appInfoServiceAdv.getConfigJson(wo.getId()));
} catch (Exception e) {
LOGGER.debug(e.getMessage());
}
boolean isAppManager = isManager || this.isAppInfoManager(personName, unitNames, groupNames, appInfo);
List<String> cateIds = business.getCategoryInfoFactory().listPeopleViewIds(personName,
unitNames, groupNames, wo.getId(), isAppManager);
if(ListTools.isNotEmpty(cateIds)){
wo.setWrapOutCategoryList(emc.fetch(cateIds, WoCategory.copier2));
}
if (StringUtils.isBlank(wo.getAppType())) {
wo.setAppType("未分类");
}
wos.add(wo);
}
SortTools.asc( wos, AppInfo.appInfoSeq_FIELDNAME);
CacheManager.put(cacheCategory, cacheKey, wos);
}
result.setData( wos );
}
}
return result;
}
}
package com.x.cms.assemble.control.jaxrs.appinfo;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.cache.Cache;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.SortTools;
import com.x.cms.assemble.control.Business;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @author sword
*/
public class ActionListHasDocumentAppType extends BaseAction {
private static Logger logger = LoggerFactory.getLogger( ActionListHasDocumentAppType.class );
protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson ) throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
String personName = effectivePerson.getDistinguishedName();
Cache.CacheKey cacheKey = new Cache.CacheKey( this.getClass(), personName);
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((List<Wo>)optional.get());
} else {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
Boolean isManager = business.isManager( effectivePerson );
List<String> appIds;
if(isManager){
appIds = business.getDocumentFactory().listApp();
}else{
appIds = business.reviewFactory().listApp(personName);
}
if(ListTools.isNotEmpty(appIds)){
final String noneType = "未分类";
List<BaseAction.Wo> apps = emc.fetch(appIds, BaseAction.Wo.copier3);
apps.stream().forEach(app -> {
if(StringUtils.isBlank(app.getAppType())){
app.setAppType(noneType);
}
});
Map<String, List<BaseAction.Wo>> appMap = apps.stream().collect(Collectors.groupingBy(BaseAction.Wo::getAppType));
List<String> appTypes = new ArrayList<>(appMap.keySet());
SortTools.asc(appTypes);
for(String appType : appTypes){
if(!appType.equals(noneType)){
wos.add( new Wo( appType, appMap.get(appType).size() ));
}
}
if(appTypes.contains(noneType)){
wos.add( new Wo( noneType, appMap.get(noneType).size() ));
}
}
result.setData( wos );
CacheManager.put(cacheCategory, cacheKey, wos);
}
}
return result;
}
public static class Wo extends GsonPropertyObject {
@FieldDescribe("栏目类别名称")
private String appType;
@FieldDescribe("栏目数量")
private Integer count;
public Wo( String _appType, Integer _count ) {
this.appType = _appType;
this.count = _count;
}
public String getAppType() {
return appType;
}
public void setAppType(String appType) {
this.appType = appType;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
}
}
package com.x.cms.assemble.control.jaxrs.appinfo;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.cache.Cache;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.SortTools;
import com.x.cms.assemble.control.Business;
import com.x.cms.core.entity.AppInfo;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* 列示有权限看到文档的指定分类应用
* @author sword
*/
public class ActionListHasDocument_WithAppType extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(ActionListHasDocument_WithAppType.class);
protected ActionResult<List<Wo>> execute(HttpServletRequest request, EffectivePerson effectivePerson, String appType)
throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
String personName = effectivePerson.getDistinguishedName();
Cache.CacheKey cacheKey = new Cache.CacheKey( this.getClass(), personName, appType);
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((List<Wo>)optional.get());
} else {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
Boolean isManager = business.isManager( effectivePerson );
List<String> appIds;
List<String> unitNames = null;
List<String> groupNames = null;
if(isManager){
appIds = business.getDocumentFactory().listApp();
}else{
appIds = business.reviewFactory().listApp(personName);
unitNames = userManagerService.listUnitNamesWithPerson(personName);
groupNames = userManagerService.listGroupNamesByPerson(personName);
}
if(ListTools.isNotEmpty(appIds)){
List<AppInfo> apps = emc.list(AppInfo.class, appIds);
for(AppInfo appInfo : apps){
Wo wo = Wo.copier2.copy(appInfo);
if(StringUtils.isBlank(wo.getAppType())){
wo.setAppType("未分类");
}
if(wo.getAppType().equals(appType)){
try {
wo.setConfig( appInfoServiceAdv.getConfigJson( wo.getId() ) );
} catch (Exception e) {
LOGGER.debug(e.getMessage());
}
boolean isAppManager = isManager || this.isAppInfoManager(personName, unitNames, groupNames, appInfo);
List<String> cateIds = business.getCategoryInfoFactory().listPeopleViewIds(personName,
unitNames, groupNames, wo.getId(), isAppManager);
if(ListTools.isNotEmpty(cateIds)){
wo.setWrapOutCategoryList(emc.fetch(cateIds, WoCategory.copier2));
}
wos.add(wo);
}
}
SortTools.asc( wos, AppInfo.appInfoSeq_FIELDNAME);
CacheManager.put(cacheCategory, cacheKey, wos);
}
result.setData( wos );
}
}
return result;
}
}
......@@ -6,6 +6,8 @@ import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.cache.Cache;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.http.ActionResult;
......@@ -14,70 +16,68 @@ import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.SortTools;
import com.x.cms.assemble.control.Business;
import com.x.cms.core.entity.AppInfo;
import org.apache.commons.lang3.StringUtils;
/**
* @author sword
*/
public class ActionListWhatICanViewAllDocType_WithAppType extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionListWhatICanViewAllDocType_WithAppType.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ActionListWhatICanViewAllDocType_WithAppType.class);
@SuppressWarnings("unchecked")
protected ActionResult<List<Wo>> execute(HttpServletRequest request, EffectivePerson effectivePerson, String appType )
throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
List<Wo> wos_out = new ArrayList<>();
Boolean isXAdmin = false;
Boolean check = true;
Business business = new Business(null);
Boolean isManager = business.isManager( effectivePerson );
Boolean isAnonymous = effectivePerson.isAnonymous();
String personName = effectivePerson.getDistinguishedName();
try {
isXAdmin = userManagerService.isManager( effectivePerson );
} catch (Exception e) {
check = false;
Exception exception = new ExceptionAppInfoProcess(e, "系统在检查用户是否是平台管理员时发生异常。Name:" + personName);
result.error(exception);
logger.error(e, effectivePerson, request, null);
}
Cache.CacheKey cacheKey = new Cache.CacheKey( this.getClass(), personName, appType, isAnonymous, isXAdmin );
Cache.CacheKey cacheKey = new Cache.CacheKey( this.getClass(), personName, appType, isAnonymous, isManager );
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((List<Wo>)optional.get());
} else {
if (check) {
try {
wos_out = listViewAbleAppInfoByPermission( personName, isAnonymous, null, appType, "全部", isXAdmin, 1000 );
} catch (Exception e) {
check = false;
Exception exception = new ExceptionAppInfoProcess(e, "系统在根据用户权限查询所有可见的分类信息时发生异常。Name:" + personName);
result.error(exception);
logger.error(e, effectivePerson, request, null);
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
business = new Business(emc);
List<String> unitNames = null;
List<String> groupNames = null;
if(!isManager && !isAnonymous) {
unitNames = userManagerService.listUnitNamesWithPerson(personName);
groupNames = userManagerService.listGroupNamesByPerson(personName);
}
if( ListTools.isNotEmpty( wos_out )){
for( Wo wo : wos_out ) {
// if( ListTools.isNotEmpty( wo.getWrapOutCategoryList() )) {
try {
wo.setConfig( appInfoServiceAdv.getConfigJson( wo.getId() ) );
} catch (Exception e) {
check = false;
Exception exception = new ExceptionAppInfoProcess(e, "系统根据ID查询栏目配置支持信息时发生异常。ID=" + wo.getId() );
result.error(exception);
logger.error(e, effectivePerson, request, null);
}
wos.add( wo );
// }
List<String> appIds = business.getAppInfoFactory().listPeopleViewAppInfoIds(personName, unitNames, groupNames, appType, isManager);
if(ListTools.isNotEmpty(appIds)){
List<AppInfo> apps = emc.list(AppInfo.class, appIds);
for(AppInfo appInfo : apps){
Wo wo = Wo.copier2.copy(appInfo);
try {
wo.setConfig(appInfoServiceAdv.getConfigJson(wo.getId()));
} catch (Exception e) {
LOGGER.debug(e.getMessage());
}
boolean isAppManager = isManager || this.isAppInfoManager(personName, unitNames, groupNames, appInfo);
List<String> cateIds = business.getCategoryInfoFactory().listPeopleViewIds(personName,
unitNames, groupNames, wo.getId(), isAppManager);
if(ListTools.isNotEmpty(cateIds)){
wo.setWrapOutCategoryList(emc.fetch(cateIds, WoCategory.copier2));
}
if (StringUtils.isBlank(wo.getAppType())) {
wo.setAppType("未分类");
}
wos.add(wo);
}
//按appInfoSeq列的值, 排个序
SortTools.asc( wos, "appInfoSeq");
SortTools.asc( wos, AppInfo.appInfoSeq_FIELDNAME);
CacheManager.put(cacheCategory, cacheKey, wos);
result.setData( wos );
}
result.setData( wos );
}
}
return result;
}
}
\ No newline at end of file
}
......@@ -430,10 +430,24 @@ public class AppInfoAction extends StandardJaxrsAction {
try {
result = new ActionListAllAppType().execute(request, effectivePerson);
} catch (Exception e) {
result = new ActionResult<>();
Exception exception = new ExceptionAppInfoProcess(e,
"系统在获取所有的栏目分类信息列表时发生异常。Name:" + effectivePerson.getDistinguishedName());
result.error(exception);
result.error(e);
logger.error(e, effectivePerson, request, null);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "获取栏目存在有权限文档的栏目分类列表.", action = ActionListHasDocumentAppType.class)
@GET
@Path("list/has/document/appType")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listHasDocumentAppType( @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request ) {
EffectivePerson effectivePerson = this.effectivePerson(request);
ActionResult<List<ActionListHasDocumentAppType.Wo>> result = new ActionResult<>();
try {
result = new ActionListHasDocumentAppType().execute(request, effectivePerson);
} catch (Exception e) {
result.error(e);
logger.error(e, effectivePerson, request, null);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
......@@ -519,6 +533,41 @@ public class AppInfoAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "获取有权限看到文档的栏目信息列表.", action = ActionListHasDocument.class)
@GET
@Path("list/has/document")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listHasDocument( @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request) {
EffectivePerson effectivePerson = this.effectivePerson(request);
ActionResult<List<BaseAction.Wo>> result = new ActionResult<>();
try {
result = new ActionListHasDocument().execute(request, effectivePerson);
} catch (Exception e) {
result.error(e);
logger.error(e, effectivePerson, request, null);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "获取有权限看到文档并指定分类的栏目列表.", action = ActionListHasDocument_WithAppType.class)
@GET
@Path("list/has/document/type/{appType}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listHasDocument_WithAppType( @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("栏目类别") @PathParam("appType") String appType) {
EffectivePerson effectivePerson = this.effectivePerson(request);
ActionResult<List<BaseAction.Wo>> result = new ActionResult<>();
try {
result = new ActionListHasDocument_WithAppType().execute(request, effectivePerson, appType);
} catch (Exception e) {
result.error(e);
logger.error(e, effectivePerson, request, null);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "列示根据过滤条件的信息栏目信息,下一页.", action = ActionListNextWithFilter.class)
@PUT
@Path("filter/list/{id}/next/{count}")
......
......@@ -7,6 +7,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import com.x.base.core.project.http.EffectivePerson;
import com.x.cms.core.entity.Document;
import com.x.cms.core.entity.Review;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.entity.JpaObject;
......@@ -36,7 +39,7 @@ public class BaseAction extends StandardJaxrsAction {
protected Cache.CacheCategory cacheCategory = new Cache.CacheCategory(AppInfo.class, CategoryInfo.class,
AppDict.class, AppDictItem.class, View.class,
ViewCategory.class, ViewFieldConfig.class);
ViewCategory.class, ViewFieldConfig.class, Review.class);
protected AppInfoServiceAdv appInfoServiceAdv = new AppInfoServiceAdv();
protected FormServiceAdv formServiceAdv = new FormServiceAdv();
......@@ -53,7 +56,7 @@ public class BaseAction extends StandardJaxrsAction {
* 2、根据人员的访问权限获取可以访问的分类信息ID列表
* 3、将栏目信息和分类信息查询出来组织在一起,如果只有分类,那么也要把栏目信息加上
* 4、如果栏目信息下没有分类,则删除栏目信息的输出
*
*
* @param personName
* @param isAnonymous
* @param inAppInfoIds
......@@ -115,7 +118,7 @@ public class BaseAction extends StandardJaxrsAction {
* 2、根据人员的发布权限获取可以发布文档的分类信息ID列表<br/>
* 3、将栏目信息和分类信息查询出来组织在一起,如果只有分类,那么也要把栏目信息加上
* 4、如果栏目信息下没有分类,则删除栏目信息的输出
*
*
* @param personName
* @param isAnonymous
* @param inAppInfoIds
......@@ -152,7 +155,7 @@ public class BaseAction extends StandardJaxrsAction {
/**
* 根据指定的栏目和分类ID,将分类组织到栏目信息中
*
*
* @param appInfoIds
* @param categoryInfoIds
* @param appType
......@@ -276,6 +279,9 @@ public class BaseAction extends StandardJaxrsAction {
static WrapCopier<AppInfo, Wo> copier2 = WrapCopierFactory.wo(AppInfo.class, Wo.class,
JpaObject.singularAttributeField(AppInfo.class, true, false), null);
static WrapCopier<AppInfo, Wo> copier3 = WrapCopierFactory.wo(AppInfo.class, Wo.class,
JpaObject.singularAttributeField(AppInfo.class, true, true), null);
}
public static class WoCategory extends CategoryInfo {
......@@ -288,8 +294,39 @@ public class BaseAction extends StandardJaxrsAction {
null, ListTools.toList(JpaObject.FieldsInvisible));
static WrapCopier<CategoryInfo, WoCategory> copier2 = WrapCopierFactory.wo(CategoryInfo.class, WoCategory.class,
JpaObject.singularAttributeField(CategoryInfo.class, true, false), null);
JpaObject.singularAttributeField(CategoryInfo.class, true, true), null);
}
/**
* 是否是栏目管理员
*
* @param person
* @param appInfo
* @return
* @throws Exception
*/
public boolean isAppInfoManager(String person, List<String> unitNames, List<String> groupNames, AppInfo appInfo) throws Exception {
if (appInfo != null) {
if (ListTools.isNotEmpty(appInfo.getManageablePersonList())) {
if (appInfo.getManageablePersonList().contains(person)) {
return true;
}
}
if (ListTools.isNotEmpty(appInfo.getManageableUnitList())) {
if (ListTools.isNotEmpty(unitNames) &&
ListTools.containsAny(unitNames, appInfo.getManageableUnitList())) {
return true;
}
}
if (ListTools.isNotEmpty(appInfo.getManageableGroupList())) {
if (ListTools.isNotEmpty(groupNames) &&
ListTools.containsAny(groupNames, appInfo.getManageableGroupList())) {
return true;
}
}
}
return false;
}
}
package com.x.cms.assemble.control.service;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.x.base.core.project.cache.CacheManager;
import com.x.cms.core.entity.enums.DocumentStatus;
import org.apache.commons.lang3.StringUtils;
......@@ -120,7 +123,7 @@ public class ReviewService {
List<String> persons = new ArrayList<>();
persons.add( document.getCreatorPerson() );
logger.debug( "refreshDocumentReview -> there are "+ persons.size() +" permission in this document: " + document.getTitle() );
refreshDocumentReview( emc, appInfo, categoryInfo, document, persons );
refreshDocumentReview( emc, document, persons );
}else if( DocumentStatus.PUBLISHED.getValue().equals( document.getDocStatus() ) ||
DocumentStatus.WAIT_PUBLISH.getValue().equals( document.getDocStatus() )) {
logger.debug( "refreshDocumentReview -> refresh review for published document: " + document.getTitle() );
......@@ -130,13 +133,13 @@ public class ReviewService {
}
//将文档新的权限与数据库中的权限进行比对,新建或者更新
logger.debug( "refreshDocumentReview -> there are "+ persons.size() +" permission in this document: " + document.getTitle() );
refreshDocumentReview( emc, appInfo, categoryInfo, document, persons );
refreshDocumentReview( emc, document, persons );
}else if( DocumentStatus.ARCHIVED.getValue().equals( document.getDocStatus() ) ) {
logger.debug( "refreshDocumentReview -> refresh review for archived document: " + document.getTitle() );
//归档的文档应该只有管理员和拟稿人能看见
List<String> persons = listPublishAndManagePersons( appInfo, categoryInfo, document );
logger.debug( "refreshDocumentReview -> there are "+ persons.size() +" permission in this document: " + document.getTitle() );
refreshDocumentReview( emc, appInfo, categoryInfo, document, persons );
refreshDocumentReview( emc, document, persons );
}
}else {
logger.debug( "refreshDocumentReview -> document not exists: " + docId );
......@@ -182,58 +185,41 @@ public class ReviewService {
return permissionObjs;
}
if( !appInfoHasPermissionControl ) {//栏目没有权限
if( !categoryHasPermissionControl ) {//分类没有权限
if( !documentHasPermissionControl ) {//文档没有权限
//栏目没有权限限制,分类没有权限限制,文档没有权限限制
if( !appInfoHasPermissionControl ) {
if( !categoryHasPermissionControl ) {
if( !documentHasPermissionControl ) {
logger.debug("栏目没有阅读权限限制,分类没有阅读权限限制,文档没有阅读权限限制。文档所有人可见:*");
permissionObjs.add( "*" );
}else {
logger.debug("栏目没有阅读权限限制,分类没有阅读权限限制,文档有阅读权限限制。文档可见范围以文档的权限为主");
//栏目没有权限限制,分类没有权限限制,文档有权限限制,以文档的权限为主
addDocumentAllPermission( permissionObjs, document, appInfo, categoryInfo);
}
}else {
if( !documentHasPermissionControl ) {//如果文档没有权限控制,则添加分类的权限就可以了
}else {//分类有权限
if( !documentHasPermissionControl ) {
logger.debug("栏目没有阅读权限限制,分类有阅读权限限制,文档没有阅读权限限制。文档可见范围以分类权限为主");
//栏目没有权限限制,分类有权限限制,文档没有权限限制,以分析权限为主
addCategoryAllPermission( permissionObjs, document, categoryInfo, appInfo );
}else {
logger.debug("栏目没有阅读权限限制,分类有阅读权限限制,文档有阅读权限限制。文档可见范围以文档权限为主,交分类可见范围");
//栏目没有权限限制,分类有权限限制,文档有权限限制,以文档权限为主
logger.debug("栏目没有阅读权限限制,分类有阅读权限限制,文档有阅读权限限制。文档可见范围以文档权限为主");
addDocumentAllPermission( permissionObjs, document, appInfo, categoryInfo);
//因为分类有权限限制,所以将分类所有权限与文档权限取交集
permissionObjs.retainAll( addCategoryAllPermission( new ArrayList<>(), document, categoryInfo, appInfo) );
}
}
}else {//栏目有权限
if( !categoryHasPermissionControl ) {//分类没有权限
if( !documentHasPermissionControl ) {//文档没有权限
if( !categoryHasPermissionControl ) {
if( !documentHasPermissionControl ) {
logger.debug("栏目有阅读权限限制,分类没有阅读权限限制,文档没有阅读权限限制。文档可见范围以栏目的权限为主");
//栏目有权限限制,分类没有权限限制,文档没有权限限制,以栏目的权限为主
addAppInfoAllPermission( permissionObjs, document, categoryInfo, appInfo );
}else {
logger.debug("栏目有阅读权限限制,分类没有阅读权限限制,文档有阅读权限限制。文档可见范围以文档的权限为主,交栏目可见范围");
//栏目有权限限制,分类没有权限限制,文档有权限限制,以文档的权限为主
logger.debug("栏目有阅读权限限制,分类没有阅读权限限制,文档有阅读权限限制。文档可见范围以文档的权限为主");
addDocumentAllPermission( permissionObjs, document, appInfo, categoryInfo);
//因为栏目有权限限制,所以将栏目所有权限与文档权限取交集
permissionObjs.retainAll( addAppInfoAllPermission( new ArrayList<>(), document, categoryInfo, appInfo ) );
}
}else {
if( !documentHasPermissionControl ) {//如果文档没有权限控制,则添加分类的权限就可以了
logger.debug("栏目有阅读权限限制,分类有阅读权限限制,文档没有阅读权限限制。文档可见范围以分类权限为主,交栏目可见范围");
//栏目有权限限制,分类有权限限制,文档没有权限限制,以分类权限为主
}else {//分类有权限
if( !documentHasPermissionControl ) {
logger.debug("栏目有阅读权限限制,分类有阅读权限限制,文档没有阅读权限限制。文档可见范围以分类权限为主");
addCategoryAllPermission( permissionObjs, document, categoryInfo, appInfo);
//因为栏目有权限限制,所以将栏目所有权限与文档权限取交集
}else {
logger.debug("栏目有阅读权限限制,分类有阅读权限限制,文档有阅读权限限制。文档可见范围以文档权限为主,交分类和栏目可见范围");
//栏目有权限限制,分类有权限限制,文档有权限限制,以文档权限为主
logger.debug("栏目有阅读权限限制,分类有阅读权限限制,文档有阅读权限限制。文档可见范围以文档权限为主");
addDocumentAllPermission( permissionObjs, document, appInfo, categoryInfo);
//因为分类有权限限制,所以将分类所有权限与文档权限取交集
permissionObjs.retainAll( addCategoryAllPermission( new ArrayList<>(), document, categoryInfo, appInfo) );
//因为栏目有权限限制,所以将栏目所有权限与文档权限取交集
}
permissionObjs.retainAll( addAppInfoAllPermission( new ArrayList<>(), document, categoryInfo, appInfo ) );
}
}
if( permissionObjs.contains("*")) {
......@@ -518,17 +504,16 @@ public class ReviewService {
objName = person.getDistinguishedName();
}
}
if( !permissionObjs.contains( objName )) {
permissionObjs.add( objName );
}
addStringToList( permissionObjs, objName );
}else if( objName.trim().endsWith( "@I" ) ) {//将Identity转换为人员
//从身份到人员
array = objName.split("@");
if( array.length == 2){
objName = userManagerService.getPersonNameWithIdentity(array[0]);
result = userManagerService.getPersonNameWithIdentity(array[0]);
}else{
result = userManagerService.getPersonNameWithIdentity( objName );
}
result = userManagerService.getPersonNameWithIdentity( objName );
permissionObjs = addStringToList( permissionObjs, result );
addStringToList( permissionObjs, result );
}else if( objName.trim().endsWith( "@U" ) ) {//将组织拆解为人员
//判断一下,如果不是顶层组织,就或者顶层组织不唯一,才将组织解析为人员
if( !userManagerService.isTopUnit( objName ) || userManagerService.countTopUnit() > 1 ) {
......@@ -536,7 +521,7 @@ public class ReviewService {
permissionObjs = addListToList( permissionObjs, persons );
}else {
//如果是顶层组织,并且顶层组织只有一个
permissionObjs = addStringToList( permissionObjs, "*" );
addStringToList( permissionObjs, "*" );
}
}else if( objName.trim().endsWith( "@G" ) ) {//将群组拆解为人员
persons = userManagerService.listPersonWithGroup( objName );
......@@ -563,7 +548,7 @@ public class ReviewService {
if( list == null ) {
list = new ArrayList<>();
}
if( !list.contains( string )) {
if(StringUtils.isNotBlank(string) && !list.contains( string )) {
list.add( string);
}
return list;
......@@ -594,17 +579,16 @@ public class ReviewService {
/**
* 将指定文档的Review刷新为指定的人员可见
* @param emc
* @param appInfo
* @param categoryInfo
* @param document
* @param permissionPersons
* @throws Exception
*/
private void refreshDocumentReview( EntityManagerContainer emc, AppInfo appInfo, CategoryInfo categoryInfo, Document document, List<String> permissionPersons) throws Exception {
private void refreshDocumentReview( EntityManagerContainer emc, Document document, List<String> permissionPersons) throws Exception {
Business business = new Business(emc);
Set<String> permissionSet = new HashSet<>(permissionPersons);
permissionPersons.clear();
//先检查该文档是否存在Review信息
List<String> oldReviewIds = business.reviewFactory().listByDocument( document.getId(), 9999 );
List<String> oldReviewIds = business.reviewFactory().listByDocument( document.getId(), null );
//先删除原来所有的Review信息
if( ListTools.isNotEmpty( oldReviewIds )) {
......@@ -612,7 +596,9 @@ public class ReviewService {
int i = 0;
for( String reviewId : oldReviewIds ){
Review oldReview = emc.find( reviewId, Review.class );
if( oldReview != null ){
if(permissionSet.contains(oldReview.getPermissionObj())){
permissionSet.remove(oldReview.getPermissionObj());
}else{
emc.remove( oldReview, CheckRemoveType.all );
i++;
if(i>99 && i % 100 ==0){
......@@ -625,13 +611,12 @@ public class ReviewService {
}
//再添加新的Review信息
if( ListTools.isNotEmpty( permissionPersons )) {
permissionPersons = removeSameValue( permissionPersons );
if( permissionSet.size() > 0) {
emc.beginTransaction( Review.class );
Person personObj = null;
String personName = null;
int i = 0;
for( String person : permissionPersons ) {
for( String person : permissionSet ) {
if( !person.equalsIgnoreCase( "*" )) {
//检查一下个人是否存在,防止姓名或者唯一标识变更过了导致文档权限不正确
personObj = userManagerService.getPerson( person );
......@@ -645,7 +630,7 @@ public class ReviewService {
//查询一下,数据库里, 是否有相同的数据,如果有,就不再添加了
oldReviewIds = business.reviewFactory().listByDocumentAndPerson( document.getId(), personName );
if( ListTools.isEmpty( oldReviewIds )) {
Review review = createReviewWithDocument( appInfo, categoryInfo, document, personName );
Review review = createReviewWithDocument( document, personName );
emc.persist( review, CheckPersistType.all );
i++;
if(i>99 && i % 100 ==0){
......@@ -657,6 +642,8 @@ public class ReviewService {
}
emc.commit();
}
CacheManager.notify(Review.class);
}
/**
......@@ -679,13 +666,11 @@ public class ReviewService {
/**
*
* 根据栏目,分类,文档信息以及可见权限来组织一个Review对象
* @param appInfo
* @param categoryInfo
* @param document
* @param person
* @return
*/
private Review createReviewWithDocument( AppInfo appInfo, CategoryInfo categoryInfo, Document document, String person ) {
private Review createReviewWithDocument( Document document, String person ) {
Review review = new Review();
review.setId( Review.createId() );
......@@ -693,21 +678,8 @@ public class ReviewService {
review.setTitle( document.getTitle() );
review.setDocStatus( document.getDocStatus() );
review.setDocumentType( document.getDocumentType() );
review.setHasIndexPic( document.getHasIndexPic() );
review.setIsTop( document.getIsTop() );
review.setDocSequence( document.getSequence() );
review.setSequenceTitle( document.getSequenceTitle() );
review.setSequenceAppAlias( document.getSequenceAppAlias() );
review.setSequenceCategoryAlias( document.getSequenceCategoryAlias() );
review.setSequenceCreatorPerson( document.getSequenceCreatorPerson( ));
review.setSequenceCreatorUnitName( document.getSequenceCreatorUnitName() );
review.setCommendCount( document.getCommendCount());
review.setCommentCount( document.getCommentCount() );
review.setViewCount( document.getViewCount() );
review.setModifyTime( document.getModifyTime() );
review.setAppAlias( document.getAppAlias() );
review.setAppId( document.getAppId() );
review.setAppName( document.getAppName() );
......@@ -730,8 +702,6 @@ public class ReviewService {
review.setCreatorUnitName( "xadmin" );
}
review.setImportBatchName( document.getImportBatchName() );
review.setPermissionObj( person );
if( "*".equals( person ) ) {
review.setPermissionObjType( "*" );
......
......@@ -613,10 +613,14 @@ public class UserManagerService {
*/
public boolean isTopUnit(String unitName) throws Exception {
if (StringUtils.isEmpty(unitName)) {
throw new Exception("unitName is empty!");
return false;
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
String[] splitName = unitName.split("@");
if(splitName.length == 2){
unitName = business.organization().unit().get(splitName[0]);
}
List<String> unitNames = business.organization().unit().listWithLevel(1);
if (ListTools.isNotEmpty(unitNames) && unitNames.contains(unitName)) {
return true;
......
......@@ -42,10 +42,12 @@ public class Review extends SliceJpaObject {
public static final String TABLE = PersistenceProperties.Review.table;
@Override
public String getId() {
return id;
}
@Override
public void setId(String id) {
this.id = id;
}
......@@ -56,6 +58,7 @@ public class Review extends SliceJpaObject {
private String id = createId();
/* 以上为 JpaObject 默认字段 */
@Override
public void onPersist() throws Exception {
}
......@@ -173,18 +176,6 @@ public class Review extends SliceJpaObject {
@CheckPersist(allowEmpty = true)
private Date publishTime;
public static final String isTop_FIELDNAME = "isTop";
@FieldDescribe("是否置顶")
@Column(name = ColumnNamePrefix + isTop_FIELDNAME)
@CheckPersist(allowEmpty = true)
private Boolean isTop = false;
public static final String hasIndexPic_FIELDNAME = "hasIndexPic";
@FieldDescribe("是否含有首页图片")
@Column(name = ColumnNamePrefix + hasIndexPic_FIELDNAME)
@CheckPersist(allowEmpty = true)
private Boolean hasIndexPic = false;
public static final String permissionObj_FIELDNAME = "permissionObj";
@FieldDescribe("权限拥有者")
@Column(length = AbstractPersistenceProperties.organization_name_length, name = ColumnNamePrefix
......@@ -199,107 +190,6 @@ public class Review extends SliceJpaObject {
@CheckPersist(allowEmpty = false)
private String permissionObjType;
public static final String importBatchName_FIELDNAME = "importBatchName";
@FieldDescribe("文件导入的批次号:一般是分类ID+时间缀")
@Column(length = JpaObject.length_128B, name = ColumnNamePrefix + importBatchName_FIELDNAME)
@CheckPersist(allowEmpty = true)
private String importBatchName;
public static final String viewCount_FIELDNAME = "viewCount";
@FieldDescribe("文档被查看次数")
@Column(name = ColumnNamePrefix + viewCount_FIELDNAME)
@CheckPersist(allowEmpty = true)
private Long viewCount = 0L;
public static final String commendCount_FIELDNAME = "commendCount";
@FieldDescribe("文档被赞次数")
@Column(name = ColumnNamePrefix + commendCount_FIELDNAME)
@CheckPersist(allowEmpty = true)
private Long commendCount = 0L;
public static final String commentCount_FIELDNAME = "commentCount";
@FieldDescribe("文档评论次数")
@Column(name = ColumnNamePrefix + commentCount_FIELDNAME)
@CheckPersist(allowEmpty = true)
private Long commentCount = 0L;
public static final String modifyTime_FIELDNAME = "modifyTime";
@FieldDescribe("文档修改时间")
@Temporal(TemporalType.TIMESTAMP)
@Column(name = ColumnNamePrefix + modifyTime_FIELDNAME)
@CheckPersist(allowEmpty = true)
private Date modifyTime;
public static final String sequenceTitle_FIELDNAME = "sequenceTitle";
@FieldDescribe("用于标题排序的sequence")
@Column(length = JpaObject.length_255B, name = ColumnNamePrefix + sequenceTitle_FIELDNAME)
@CheckPersist(allowEmpty = true)
private String sequenceTitle = "";
public static final String sequenceAppAlias_FIELDNAME = "sequenceAppAlias";
@FieldDescribe("用于栏目别名排序的sequence")
@Column(length = JpaObject.length_255B, name = ColumnNamePrefix + sequenceAppAlias_FIELDNAME)
@CheckPersist(allowEmpty = true)
private String sequenceAppAlias = "";
public static final String sequenceCategoryAlias_FIELDNAME = "sequenceCategoryAlias";
@FieldDescribe("用于分类别名排序的sequence")
@Column(length = JpaObject.length_255B, name = ColumnNamePrefix + sequenceCategoryAlias_FIELDNAME)
@CheckPersist(allowEmpty = true)
private String sequenceCategoryAlias = "";
public static final String sequenceCreatorPerson_FIELDNAME = "sequenceCreatorPerson";
@FieldDescribe("用于创建者排序的sequence")
@Column(length = JpaObject.length_255B, name = ColumnNamePrefix + sequenceCreatorPerson_FIELDNAME)
@CheckPersist(allowEmpty = true)
private String sequenceCreatorPerson = "";
public static final String sequenceCreatorUnitName_FIELDNAME = "sequenceCreatorUnitName";
@FieldDescribe("用于创建者组织排序的sequence")
@Column(length = JpaObject.length_255B, name = ColumnNamePrefix + sequenceCreatorUnitName_FIELDNAME)
@CheckPersist(allowEmpty = true)
private String sequenceCreatorUnitName = "";
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public Long getViewCount() {
return viewCount;
}
public void setViewCount(Long viewCount) {
this.viewCount = viewCount;
}
public Long getCommendCount() {
return commendCount;
}
public void setCommendCount(Long commendCount) {
this.commendCount = commendCount;
}
public Long getCommentCount() {
return commentCount;
}
public void setCommentCount(Long commentCount) {
this.commentCount = commentCount;
}
public String getImportBatchName() {
return importBatchName;
}
public void setImportBatchName(String importBatchName) {
this.importBatchName = importBatchName;
}
public String getDocumentType() {
return documentType;
}
......@@ -428,22 +318,6 @@ public class Review extends SliceJpaObject {
this.docCreateTime = docCreateTime;
}
public Boolean getIsTop() {
return isTop;
}
public void setIsTop(Boolean isTop) {
this.isTop = isTop;
}
public Boolean getHasIndexPic() {
return hasIndexPic;
}
public void setHasIndexPic(Boolean hasIndexPic) {
this.hasIndexPic = hasIndexPic;
}
public String getPermissionObj() {
return permissionObj;
}
......@@ -468,122 +342,10 @@ public class Review extends SliceJpaObject {
this.docSequence = getSequenceString(docSequence);
}
public String getSequenceTitle() {
return sequenceTitle;
}
public void setSequenceTitle(String sequenceTitle) {
this.sequenceTitle = getSequenceString(sequenceTitle);
}
public String getSequenceAppAlias() {
return sequenceAppAlias;
}
public void setSequenceAppAlias(String sequenceAppAlias) {
this.sequenceAppAlias = getSequenceString(sequenceAppAlias);
}
public String getSequenceCategoryAlias() {
return sequenceCategoryAlias;
}
public void setSequenceCategoryAlias(String sequenceCategoryAlias) {
this.sequenceCategoryAlias = getSequenceString(sequenceCategoryAlias);
}
public String getSequenceCreatorPerson() {
return sequenceCreatorPerson;
}
public void setSequenceCreatorPerson(String sequenceCreatorPerson) {
this.sequenceCreatorPerson = getSequenceString(sequenceCreatorPerson);
}
public String getSequenceCreatorUnitName() {
return sequenceCreatorUnitName;
}
public void setSequenceCreatorUnitName(String sequenceCreatorUnitName) {
this.sequenceCreatorUnitName = getSequenceString(sequenceCreatorUnitName);
}
public static final String[] sortableFieldNames = { appAlias_FIELDNAME, appId_FIELDNAME, appName_FIELDNAME,
categoryAlias_FIELDNAME, categoryId_FIELDNAME, categoryName_FIELDNAME, commendCount_FIELDNAME,
commentCount_FIELDNAME, creatorPerson_FIELDNAME, creatorTopUnitName_FIELDNAME, creatorUnitName_FIELDNAME,
docStatus_FIELDNAME, hasIndexPic_FIELDNAME, isTop_FIELDNAME, modifyTime_FIELDNAME, publishTime_FIELDNAME,
title_FIELDNAME, viewCount_FIELDNAME };
public static Boolean isFieldInSequence(String orderField) {
// 判断排序列情况
if (StringUtils.isEmpty(orderField)) {
return true;
}
if (id_FIELDNAME.equalsIgnoreCase(orderField)) {
return true;
}
if (sequence_FIELDNAME.equalsIgnoreCase(orderField)) {
return true;
}
if (title_FIELDNAME.equalsIgnoreCase(orderField)) {
return true;
}
if (appAlias_FIELDNAME.equalsIgnoreCase(orderField)) {
return true;
}
if (appName_FIELDNAME.equalsIgnoreCase(orderField)) {
return true;
}
if (categoryAlias_FIELDNAME.equalsIgnoreCase(orderField)) {
return true;
}
if (categoryName_FIELDNAME.equalsIgnoreCase(orderField)) {
return true;
}
if (creatorPerson_FIELDNAME.equalsIgnoreCase(orderField)) {
return true;
}
if (creatorUnitName_FIELDNAME.equalsIgnoreCase(orderField)) {
return true;
}
return false;
}
public static String getSequnceFieldNameWithProperty(String fieldName) {
if (sequence_FIELDNAME.equalsIgnoreCase(fieldName)) {
return sequence_FIELDNAME;
}
if (id_FIELDNAME.equalsIgnoreCase(fieldName)) {
return id_FIELDNAME;
}
if (title_FIELDNAME.equalsIgnoreCase(fieldName)) {
return sequenceTitle_FIELDNAME;
}
if (appAlias_FIELDNAME.equalsIgnoreCase(fieldName)) {
return sequenceAppAlias_FIELDNAME;
}
if (appName_FIELDNAME.equalsIgnoreCase(fieldName)) {
return sequenceAppAlias_FIELDNAME;
}
if (categoryAlias_FIELDNAME.equalsIgnoreCase(fieldName)) {
return sequenceCategoryAlias_FIELDNAME;
}
if (categoryName_FIELDNAME.equalsIgnoreCase(fieldName)) {
return sequenceCategoryAlias_FIELDNAME;
}
if (creatorPerson_FIELDNAME.equalsIgnoreCase(fieldName)) {
return sequenceCreatorPerson_FIELDNAME;
}
if (creatorUnitName_FIELDNAME.equalsIgnoreCase(fieldName)) {
return sequenceCreatorUnitName_FIELDNAME;
}
return sequence_FIELDNAME;
}
private String getSequenceString(String sequenceString) {
if (StringUtils.length(sequenceString) > 60) {
return StringUtils.substring(sequenceString, 0, 60);
}
return sequenceString;
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册