All Downloads are FREE. Search and download functionalities are using the official Maven repository.

zikai.apijson.framework.APIJSONParser Maven / Gradle / Ivy

The newest version!
package zikai.apijson.framework;


import com.alibaba.fastjson2.JSONObject;

import zikai.apijson.core.RequestMethod;
import zikai.apijson.core.orm.AbstractParser;
import zikai.apijson.core.orm.FunctionParser;
import zikai.apijson.core.orm.Parser;
import zikai.apijson.core.orm.SQLConfig;
import zikai.apijson.core.orm.SQLExecutor;
import zikai.apijson.core.orm.Verifier;

import static zikai.apijson.framework.APIJSONConstant.*;


/**请求解析器
 * @author Lemon
 */
public class APIJSONParser extends AbstractParser {
	public static final String TAG = "APIJSONParser";

	public static APIJSONCreator APIJSON_CREATOR;
	static {
		APIJSON_CREATOR = new APIJSONCreator<>();
	}
	
	public APIJSONParser() {
		super();
	}

	public APIJSONParser(RequestMethod method) {
		super(method);
	}
	public APIJSONParser(RequestMethod method, boolean needVerify) {
		super(method, needVerify);
	}

	@Override
	public Parser createParser() {
		return (Parser) APIJSON_CREATOR.createParser();
	}
	@Override
	public FunctionParser createFunctionParser() {
		return APIJSON_CREATOR.createFunctionParser();
	}

	@Override
	public Verifier createVerifier() {
		return (Verifier) APIJSON_CREATOR.createVerifier();
	}
	
	@Override
	public SQLConfig createSQLConfig() {
		return APIJSON_CREATOR.createSQLConfig();
	}
	@Override
	public SQLExecutor createSQLExecutor() {
		return APIJSON_CREATOR.createSQLExecutor();
	}


	@Override
	public JSONObject parseResponse(JSONObject request) throws Exception {
		//补充format
		if (request != null) {
//			if (request.get(FORMAT) == null) {
//				throw new Exception("FORMAT is null");
//			}
//
//			if (request.get(DEFAULTS) == null) {
//				throw new Exception("DEFAULTS is null");
//			}
		}
		return super.parseResponse(request);
	}

	private FunctionParser functionParser;
	public FunctionParser getFunctionParser() {
		return functionParser;
	}
	@Override
	public Object onFunctionParse(String key, String function, String parentPath, String currentName, JSONObject currentObject) throws Exception {
		if (functionParser == null) {
			functionParser = createFunctionParser();
			functionParser.setMethod(getMethod());
			functionParser.setTag(getTag());
			functionParser.setVersion(getVersion());
			functionParser.setRequest(requestObject);
		}
		functionParser.setKey(key);
		functionParser.setParentPath(parentPath);
		functionParser.setCurrentName(currentName);
		functionParser.setCurrentObject(currentObject);
		
		return functionParser.invoke(function, currentObject);
	}


	@Override
	public APIJSONObjectParser createObjectParser(JSONObject request, String parentPath, SQLConfig arrayConfig
			, boolean isSubquery, boolean isTable, boolean isArrayMainTable) throws Exception {

		return new APIJSONObjectParser(request, parentPath, arrayConfig, isSubquery, isTable, isArrayMainTable) {

			//			@Override
			//			protected APIJSONSQLConfig newQueryConfig() {
			//				if (itemConfig != null) {
			//					return itemConfig;
			//				}
			//				return super.newQueryConfig();
			//			}

			//导致最多评论的(Strong 30个)的那个动态详情界面Android(82001)无姓名和头像,即User=null
			//			@Override
			//			protected void onComplete() {
			//				if (response != null) {
			//					putQueryResult(path, response);//解决获取关联数据时requestObject里不存在需要的关联数据
			//				}
			//			}

		}.setMethod(getMethod()).setParser(this);
	}



	@Override
	public void onVerifyContent() throws Exception {
		if (requestObject.get(VERSION) == null) {
			throw new Exception("request version is null");
		}
		super.onVerifyContent();
	}


	//	//可重写来设置最大查询数量
	//	@Override
	//	public int getMaxQueryCount() {
	//		return 50;
	//	}
	

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy