ActionWorkCanDismantling.java 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
package com.x.okr.assemble.control.jaxrs.okrworkbaseinfo;

import javax.servlet.http.HttpServletRequest;

import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.WrapOutBoolean;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.okr.assemble.control.OkrUserCache;
import com.x.okr.assemble.control.jaxrs.okrworkbaseinfo.exception.ExceptionGetOkrUserCache;
import com.x.okr.assemble.control.jaxrs.okrworkbaseinfo.exception.ExceptionUserNoLogin;
import com.x.okr.assemble.control.jaxrs.okrworkbaseinfo.exception.ExceptionWorkIdEmpty;

public class ActionWorkCanDismantling extends BaseAction {

	private static  Logger logger = LoggerFactory.getLogger( ActionWorkCanDismantling.class );
	
	protected ActionResult<WrapOutBoolean> execute( HttpServletRequest request,EffectivePerson effectivePerson, String id ) throws Exception {
		ActionResult<WrapOutBoolean> result = new ActionResult<>();
		WrapOutBoolean wrap = new WrapOutBoolean();
		Boolean check = true;
		String loginIdentity = null;
		OkrUserCache  okrUserCache  = null;
		if( check ){
			try {
				okrUserCache = okrUserInfoService.getOkrUserCacheWithPersonName( effectivePerson.getDistinguishedName() );
			} catch ( Exception e ) {
				check = false;
				Exception exception = new ExceptionGetOkrUserCache( e, effectivePerson.getDistinguishedName()  );
				result.error( exception );
				logger.error( e, effectivePerson, request, null);
			}
		}		
		if( check && ( okrUserCache == null || okrUserCache.getLoginIdentityName() == null ) ){
			check = false;
			Exception exception = new ExceptionUserNoLogin( effectivePerson.getDistinguishedName()  );
			result.error( exception );
		}
		if( check ){
			if( okrUserCache.getLoginIdentityName() == null || okrUserCache.getLoginIdentityName().isEmpty() ){
				check = false;
				Exception exception = new ExceptionUserNoLogin( effectivePerson.getDistinguishedName()  );
				result.error( exception );
			}
		}
		if( check ){
			loginIdentity = okrUserCache.getLoginIdentityName() ;
			if( id == null || id.isEmpty() ){
				Exception exception = new ExceptionWorkIdEmpty();
				result.error( exception );
			}else{
				try {
					if( okrWorkBaseInfoService.canDismantlingWorkByIdentity( id, loginIdentity ) ){
						wrap.setValue( true );
						result.setData( wrap );
					}else{
						wrap.setValue( false );
						result.setData( wrap );
					}
				} catch (Exception e) {
					result.error( e );
					logger.error(e);
					wrap.setValue( false );
					result.setData( wrap );
				}
			}
		}else{
			wrap.setValue( false );
			result.setData( wrap );
		}				
		return result;
	}
	
}