ActionListWhatICanViewArticle.java 3.0 KB
Newer Older
R
roo00 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package com.x.cms.assemble.control.jaxrs.appinfo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.x.base.core.project.cache.ApplicationCache;
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 net.sf.ehcache.Element;

R
roo00 已提交
18
public class ActionListWhatICanViewArticle extends BaseAction {
R
roo00 已提交
19

R
roo00 已提交
20
	private static  Logger logger = LoggerFactory.getLogger(ActionListWhatICanViewArticle.class);
R
roo00 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

	@SuppressWarnings("unchecked")
	protected ActionResult<List<Wo>> execute(HttpServletRequest request, EffectivePerson effectivePerson)
			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;
		Boolean isAnonymous = effectivePerson.isAnonymous();
		String personName = effectivePerson.getDistinguishedName();
		
		if( "xadmin".equalsIgnoreCase( effectivePerson.getName() ) ) {
			personName = "xadmin";
		}
		
		try {
			isXAdmin = userManagerService.isManager(request, effectivePerson );
		} catch (Exception e) {
			check = false;
			Exception exception = new ExceptionAppInfoProcess(e, "系统在检查用户是否是平台管理员时发生异常。Name:" + personName);
			result.error(exception);
			logger.error(e, effectivePerson, request, null);
		}
		
R
roo00 已提交
46
		String cacheKey = ApplicationCache.concreteCacheKey(personName,  "all", "Article", isXAdmin);
R
roo00 已提交
47 48 49 50 51 52 53 54 55
		Element element = cache.get(cacheKey);

		if ((null != element) && (null != element.getObjectValue())) {
			wos = (List<Wo>) element.getObjectValue();
			result.setData(wos);
		} else {
			if (check) {
				if (isXAdmin) {
					try {
R
roo00 已提交
56
						wos = listViewAbleAppInfoByPermission( personName, isAnonymous, null,  "all", "信息", isXAdmin, 1000 );
R
roo00 已提交
57 58 59 60 61 62 63 64
					} catch (Exception e) {
						check = false;
						Exception exception = new ExceptionAppInfoProcess(e, "系统查询所有可见的分类信息时发生异常[管理员]。Name:" + personName);
						result.error(exception);
						logger.error(e, effectivePerson, request, null);
					}
				} else {
					try {
R
roo00 已提交
65
						wos_out = listViewAbleAppInfoByPermission( personName, isAnonymous, null,  "all", "信息", isXAdmin, 1000 );
R
roo00 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
						for( Wo wo : wos_out ) {
							if( ListTools.isNotEmpty( wo.getWrapOutCategoryList() )) {
								wos.add( wo );
							}
						}
					} catch (Exception e) {
						check = false;
						Exception exception = new ExceptionAppInfoProcess(e,
								"系统在根据用户权限查询所有可见的分类信息时发生异常。Name:" + personName);
						result.error(exception);
						logger.error(e, effectivePerson, request, null);
					}
				}
			}
		}
		if(ListTools.isNotEmpty( wos)) {
			SortTools.asc( wos, "appInfoSeq");
		}
R
fix  
roo00 已提交
84
		cache.put(new Element( cacheKey, wos ));
R
roo00 已提交
85 86 87 88
		result.setData(wos);
		return result;
	}
}