ActionDelete.java 3.6 KB
Newer Older
R
roo00 已提交
1
package com.x.teamwork.assemble.control.jaxrs.extfield;
R
fix  
roo00 已提交
2

R
roo00 已提交
3 4 5
import java.util.ArrayList;
import java.util.List;

R
fix  
roo00 已提交
6 7 8 9
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;

R
roo00 已提交
10 11 12 13
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
R
fix  
roo00 已提交
14 15 16 17 18 19
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.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
R
roo00 已提交
20
import com.x.teamwork.core.entity.Dynamic;
L
luojing 已提交
21
import com.x.teamwork.core.entity.CustomExtFieldRele;
R
fix  
roo00 已提交
22 23 24 25 26 27 28

public class ActionDelete extends BaseAction {

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

	protected ActionResult<Wo> execute(HttpServletRequest request, EffectivePerson effectivePerson, String flag) throws Exception {
		ActionResult<Wo> result = new ActionResult<>();
L
luojing 已提交
29
		CustomExtFieldRele customExtFieldRele = null;
R
roo00 已提交
30
		Wo wo = new Wo();
R
fix  
roo00 已提交
31 32 33 34
		Boolean check = true;

		if ( StringUtils.isEmpty( flag ) ) {
			check = false;
L
luojing 已提交
35
			Exception exception = new CustomExtFieldReleFlagForQueryEmptyException();
R
fix  
roo00 已提交
36 37 38
			result.error( exception );
		}

39
		if( Boolean.TRUE.equals( check ) ){
R
fix  
roo00 已提交
40
			try {
L
luojing 已提交
41 42
				customExtFieldRele = customExtFieldReleQueryService.get(flag);
				if ( customExtFieldRele == null) {
R
fix  
roo00 已提交
43
					check = false;
L
luojing 已提交
44
					Exception exception = new CustomExtFieldReleNotExistsException(flag);
R
fix  
roo00 已提交
45 46 47 48
					result.error( exception );
				}
			} catch (Exception e) {
				check = false;
L
luojing 已提交
49
				Exception exception = new CustomExtFieldReleQueryException(e, "根据指定flag查询扩展属性关联信息对象时发生异常。flag:" + flag);
R
fix  
roo00 已提交
50 51 52 53 54
				result.error(exception);
				logger.error(e, effectivePerson, request, null);
			}
		}
		
55
		if( Boolean.TRUE.equals( check ) ){
R
fix  
roo00 已提交
56
			try {
L
luojing 已提交
57
				customExtFieldRelePersistService.delete(flag, effectivePerson );
R
fix  
roo00 已提交
58 59
				
				// 更新缓存
L
luojing 已提交
60
				ApplicationCache.notify( CustomExtFieldRele.class );
R
fix  
roo00 已提交
61
				
L
luojing 已提交
62
				wo.setId( customExtFieldRele.getId() );
R
roo00 已提交
63
				
R
fix  
roo00 已提交
64 65
			} catch (Exception e) {
				check = false;
L
luojing 已提交
66
				Exception exception = new CustomExtFieldReleQueryException(e, "根据指定flag删除扩展属性关联信息对象时发生异常。flag:" + flag);
R
fix  
roo00 已提交
67 68 69 70
				result.error(exception);
				logger.error(e, effectivePerson, request, null);
			}
		}
71
		if( Boolean.TRUE.equals( check ) ){
R
fix  
roo00 已提交
72
			try {					
L
luojing 已提交
73
				Dynamic dynamic = dynamicPersistService.projectExtFieldReleDeleteDynamic( customExtFieldRele, effectivePerson);
R
roo00 已提交
74 75 76 77 78 79 80
				if( dynamic != null ) {
					List<WoDynamic> dynamics = new ArrayList<>();
					dynamics.add( WoDynamic.copier.copy( dynamic ) );
					if( wo != null ) {
						wo.setDynamics(dynamics);
					}
				}
R
fix  
roo00 已提交
81 82 83 84
			} catch (Exception e) {
				logger.error(e, effectivePerson, request, null);
			}	
		}
R
roo00 已提交
85
		result.setData( wo );
R
fix  
roo00 已提交
86 87 88 89
		return result;
	}

	public static class Wo extends WoId {
R
roo00 已提交
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
		
		@FieldDescribe("操作引起的动态内容")
		List<WoDynamic> dynamics = new ArrayList<>();

		public List<WoDynamic> getDynamics() {
			return dynamics;
		}

		public void setDynamics(List<WoDynamic> dynamics) {
			this.dynamics = dynamics;
		}
		
	}
	
	public static class WoDynamic extends Dynamic{

		private static final long serialVersionUID = -5076990764713538973L;

		public static WrapCopier<Dynamic, WoDynamic> copier = WrapCopierFactory.wo( Dynamic.class, WoDynamic.class, null, JpaObject.FieldsInvisible);
		
		private Long rank = 0L;

		public Long getRank() {
			return rank;
		}

		public void setRank(Long rank) {
			this.rank = rank;
		}		
R
fix  
roo00 已提交
119 120
	}
}