@ParamDataSet, @ParamVariable 필수 옵션 설정 추가.
This commit is contained in:
@@ -24,7 +24,7 @@ public class NexacroException extends Exception {
|
||||
public static final String DEFAULT_MESSAGE = "An Error Occured. check the ErrorCode for detail of error infomation.";
|
||||
|
||||
private int errorCode = DEFAULT_ERROR_CODE;
|
||||
private String errorMsg = DEFAULT_MESSAGE;
|
||||
private String errorMsg;
|
||||
|
||||
/**
|
||||
* 기본 생성자이다.
|
||||
|
||||
@@ -5,8 +5,6 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import com.nexacro.spring.context.NexacroContextHolder;
|
||||
|
||||
/**
|
||||
* <p><code>DataSet</code>을 List혹은 POJO형태의 데이터로 변환을 수행하기 위한 annotation이다.
|
||||
*
|
||||
@@ -17,15 +15,23 @@ import com.nexacro.spring.context.NexacroContextHolder;
|
||||
* @author Park SeongMin
|
||||
* @since 07.28.2015
|
||||
* @version 1.0
|
||||
* @see NexacroContextHolder
|
||||
* @see ParamVariable
|
||||
*/
|
||||
@Target({ java.lang.annotation.ElementType.PARAMETER })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface ParamDataSet {
|
||||
/**
|
||||
* 데이터셋의 식별자
|
||||
* <code>DataSet</code>의 식별자
|
||||
* @return dsName
|
||||
*/
|
||||
public abstract String name();
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Whether the parameter is required.
|
||||
* <p>Default is {@code true}, leading to an exception thrown in case
|
||||
* of the parameter missing in the request. Switch this to {@code false}
|
||||
* if you prefer a {@code null} in case of the parameter missing.
|
||||
*/
|
||||
boolean required() default true;
|
||||
}
|
||||
@@ -5,8 +5,6 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import com.nexacro.spring.context.NexacroContextHolder;
|
||||
|
||||
/**
|
||||
* <p><code>Variable</code>을 Primitive 형태의 데이터로 변환을 수행하기 위한 annotation이다.
|
||||
*
|
||||
@@ -17,11 +15,24 @@ import com.nexacro.spring.context.NexacroContextHolder;
|
||||
* @author Park SeongMin
|
||||
* @since 07.28.2015
|
||||
* @version 1.0
|
||||
* @see NexacroContextHolder
|
||||
* @see ParamDataSet
|
||||
*/
|
||||
@Target({ java.lang.annotation.ElementType.PARAMETER })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface ParamVariable {
|
||||
public abstract String name();
|
||||
|
||||
/**
|
||||
* <code>Variable</code>식별자
|
||||
* @return dsName
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Whether the parameter is required.
|
||||
* <p>Default is {@code true}, leading to an exception thrown in case
|
||||
* of the parameter missing in the request. Switch this to {@code false}
|
||||
* if you prefer a {@code null} in case of the parameter missing.
|
||||
*/
|
||||
boolean required() default true;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -13,6 +14,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
@@ -275,9 +277,12 @@ public class NexacroMethodArgumentResolver implements HandlerMethodArgumentResol
|
||||
String dsName = paramDataSet.name();
|
||||
DataSet dataSet = nexacroCachedData.getPlatformData().getDataSet(dsName);
|
||||
if(dataSet == null) {
|
||||
if(logger.isDebugEnabled()) {
|
||||
if(logger.isDebugEnabled()) {
|
||||
logger.debug("@ParamDataSet '" + dsName + "' argument is null.");
|
||||
}
|
||||
if (paramDataSet.required()) {
|
||||
handleMissingValue(paramDataSet.name(), param);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -330,6 +335,9 @@ public class NexacroMethodArgumentResolver implements HandlerMethodArgumentResol
|
||||
if(logger.isDebugEnabled()) {
|
||||
logger.debug("@ParamVariable '" + varName + "' argument is null.");
|
||||
}
|
||||
if (paramVariable.required()) {
|
||||
handleMissingValue(paramVariable.name(), param);
|
||||
}
|
||||
return null;
|
||||
//throw new IllegalArgumentException("invalid @ParamVariable. ex)@ParamVariable(name=\"variableName\") Object var");
|
||||
}
|
||||
@@ -382,6 +390,10 @@ public class NexacroMethodArgumentResolver implements HandlerMethodArgumentResol
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void handleMissingValue(String name, MethodParameter parameter) throws NexacroConvertException {
|
||||
throw new MissingNexacroParameterException(name, parameter.getParameterType().getSimpleName());
|
||||
}
|
||||
|
||||
private Object getAttribute(NativeWebRequest nativeWebRequest, String attrName) {
|
||||
return nativeWebRequest.getAttribute(attrName, RequestAttributes.SCOPE_REQUEST);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user