use of com.publiccms.common.base.BaseMethod in project PublicCMS-preview by sanluan.
the class MethodController method method.
/**
* 接口指令统一分发
*
* @param name
* @param appToken
* @param request
* @param response
* @return result
*/
@RequestMapping("method/{name}")
public Object method(@PathVariable String name, String appToken, HttpServletRequest request, HttpServletResponse response) {
BaseMethod method = methodMap.get(name);
if (null != method) {
try {
if (method.needAppToken()) {
SysAppToken token = appTokenService.getEntity(appToken);
if (null == token) {
return NEED_APP_TOKEN_MAP;
}
SysApp app = appService.getEntity(token.getAppId());
if (null == app) {
return NEED_APP_TOKEN_MAP;
}
}
Map<String, Object> map = new HashMap<>();
String[] paramters = request.getParameterValues("paramters");
if (CommonUtils.notEmpty(paramters) && paramters.length >= method.minParamtersNumber()) {
List<TemplateModel> list = new ArrayList<>();
for (String paramter : paramters) {
list.add(getObjectWrapper().wrap(paramter));
}
map.put("result", method.exec(list));
return map;
} else if (CommonUtils.empty(paramters) && 0 == method.minParamtersNumber()) {
map.put("result", method.exec(null));
return map;
} else {
map.put(ERROR, "paramtersError");
return map;
}
} catch (TemplateModelException e) {
log.error(e.getMessage(), e);
Map<String, String> map = new HashMap<>();
map.put(ERROR, ApiController.EXCEPTION);
return map;
}
} else {
return ApiController.NOT_FOUND_MAP;
}
}
use of com.publiccms.common.base.BaseMethod in project PublicCMS-preview by sanluan.
the class DirectiveComponent method init.
@Autowired
private void init(List<AbstractTemplateDirective> templateDirectiveList, List<AbstractTaskDirective> taskDirectiveList, List<BaseMethod> methodList) {
for (AbstractTemplateDirective directive : templateDirectiveList) {
if (null == directive.getName()) {
directive.setName(getDirectiveName(directive.getClass().getSimpleName()));
}
templateDirectiveMap.put(directive.getName(), directive);
}
log.info(new StringBuilder().append(templateDirectiveMap.size()).append(" template directives created:").append(templateDirectiveMap.keySet()).toString());
for (AbstractTaskDirective directive : taskDirectiveList) {
if (null == directive.getName()) {
directive.setName(getDirectiveName(directive.getClass().getSimpleName()));
}
taskDirectiveMap.put(directive.getName(), directive);
}
log.info(new StringBuilder().append(taskDirectiveMap.size()).append(" task directives created:").append(taskDirectiveMap.keySet()).toString());
for (BaseMethod method : methodList) {
if (null == method.getName()) {
method.setName(StringUtils.uncapitalize(method.getClass().getSimpleName().replaceAll(methodRemoveRegex, BLANK)));
}
methodMap.put(method.getName(), method);
}
log.info(new StringBuilder().append(methodMap.size()).append(" methods created:").append(methodMap.keySet()).toString());
}
Aggregations