ActionRefreshDocumentPermission.java 3.6 KB
Newer Older
R
roo00 已提交
1 2 3 4
package com.x.cms.assemble.control.jaxrs.permission;

import com.google.gson.JsonElement;
import com.x.base.core.entity.JpaObject;
R
update  
roo00 已提交
5
import com.x.base.core.project.annotation.AuditLog;
R
roo00 已提交
6 7 8 9 10 11
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
R
fix  
roo00 已提交
12
import com.x.base.core.project.tools.ListTools;
R
roo00 已提交
13 14 15
import com.x.cms.assemble.control.ExceptionWrapInConvert;
import com.x.cms.assemble.control.jaxrs.permission.element.PermissionInfo;
import com.x.cms.core.entity.Document;
R
update  
roo00 已提交
16 17 18 19 20
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
R
roo00 已提交
21 22 23 24 25

public class ActionRefreshDocumentPermission extends BaseAction {

	private static Logger logger = LoggerFactory.getLogger(ActionRefreshDocumentPermission.class);

R
update  
roo00 已提交
26
	@AuditLog(operation = "刷新文档权限")
R
roo00 已提交
27
	protected ActionResult<Wo> execute(HttpServletRequest request, EffectivePerson effectivePerson, JsonElement jsonElement ) throws Exception {
R
roo00 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
		ActionResult<Wo> result = new ActionResult<>();
		Document document = null;
		Wi wi = null;
		Boolean check = true;

		try {
			wi = this.convertToWrapIn(jsonElement, Wi.class);
		} catch (Exception e) {
			check = false;
			Exception exception = new ExceptionWrapInConvert(e, jsonElement);
			result.error(exception);
			logger.error(e, effectivePerson, request, null);
		}

		if (check) {
R
fix  
roo00 已提交
43
			if ( StringUtils.isEmpty(wi.getDocId())) {
R
roo00 已提交
44 45 46 47 48 49 50
				check = false;
				Exception exception = new ExceptionServiceLogic("文档ID为空,无法为文档添加权限。");
				result.error(exception);
			}
		}

		if (check) {
R
fix  
roo00 已提交
51
			if ( ListTools.isEmpty(wi.getPermissionList())) {
52 53 54
				check = false;
				Exception exception = new ExceptionServiceLogic("文档权限为空,该文档将没有任何用户可以访问。ID:" + wi.getDocId());
				result.error(exception);
R
roo00 已提交
55 56 57 58 59
			}
		}

		if (check) {
			try {
R
roo00 已提交
60
				document = documentQueryService.get(wi.getDocId());
R
roo00 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
				if (document == null) {
					check = false;
					Exception exception = new ExceptionServiceLogic("文档不存在。ID:" + wi.getDocId());
					result.error(exception);
				}
			} catch (Exception e) {
				check = false;
				Exception exception = new ExceptionServiceLogic(e, "系统在根据文档ID查询文档信息时发生异常。ID:" + wi.getDocId());
				result.error(exception);
				logger.error(e, effectivePerson, request, null);
			}
		}

		if (check) {
			try {
76
				documentPersistService.refreshDocumentPermission(document.getId(), wi.getPermissionList());
R
roo00 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
			} catch (Exception e) {
				check = false;
				Exception exception = new ExceptionServiceLogic(e, "系统在为文档设置用户访问权限过程中发生异常。ID:" + wi.getDocId());
				result.error(exception);
				logger.error(e, effectivePerson, request, null);
			}

		}
		return result;
	}

	public static class Wi {

		public static List<String> Excludes = new ArrayList<String>(JpaObject.FieldsUnmodify);

		@FieldDescribe("文档ID.")
		private String docId = null;

		@FieldDescribe("文档权限列表:List<PermissionInfo>")
		private List<PermissionInfo> permissionList = null;

		public String getDocId() {
			return docId;
		}

		public List<PermissionInfo> getPermissionList() {
			return permissionList;
		}

		public void setDocId(String docId) {
			this.docId = docId;
		}

		public void setPermissionList(List<PermissionInfo> permissionList) {
			this.permissionList = permissionList;
		}
	}

	public static class Wo extends WoId {

	}
}