@Override public Object apply(ActionParams params) { try { Map<String, Object> map = params.toMap(); engine.setContextVariable(PARAMS, Collections.unmodifiableMap(map)); Object value = JsConvert.convert(module.eval(map)); log.debug("Result : {}", value); if (returnTypeDefined && null != value && returnType.isSimpleType()) { value = Converts.convert(value, returnType.asSimpleType().getJavaType()); } return value; }catch (RuntimeException e) { throw e; }catch (Exception e) { throw new RuntimeException(e.getMessage(), e); }finally { engine.removeContextVariable(PARAMS); } }
Class<?> toJavaType(MType type) { if(type.isSimpleType()) { return type.asSimpleType().getJavaType(); } if(type.isCollectionType()) { return Array.newInstance(toJavaType(type.asCollectionType().getElementType()), 0).getClass(); } if(type.isComplexType() || type.isDictionaryType() || type.isTypeRef()) { return Map.class; } if(type.isObjectType()) { return Object.class; } throw new IllegalStateException("Unsupported data type '" + type + "'"); }
MSimpleType type = p.getType().asSimpleType();
void mappingBeanProperty(MetaField f, BeanProperty bp) { if(null == bp) { return; } if(null != bp && !Strings.isEmpty(f.getType())) { MType mtype = MTypes.getMType(bp.getType(), bp.getGenericType()); if(mtype.isSimpleType()) { f.setType(mtype.asSimpleType().getJdbcType().getName()); if(MSimpleTypes.STRING.equals(mtype) && null == f.getLength()) { f.setLength(255); } } } }
arg.setType(type.asSimpleType().getJavaType()); return; MType elementType = type.asCollectionType().getElementType(); if(elementType.isSimpleType()) { arg.setType(Array.newInstance(elementType.asSimpleType().getJavaType(),0).getClass()); }else if(elementType.isObjectType()){ arg.setType(Object[].class);
@Override public Object apply(ActionParams params) { Map<String,Object> map = params.toMap(); Object result; if(command.getMetadata().isSelect()) { //todo: page query, total count Query query = dao.createQuery(command).params(map); if(null != returnType) { if(returnType.isSimpleType()) { result = Converts.convert(query.scalarValueOrNull(), returnType.asSimpleType().getJavaType()); }else if(returnType.isCollectionType() && returnType.asCollectionType().getElementType().isSimpleType()) { result = query.scalars().list(returnType.asCollectionType().getElementType().asSimpleType().getJavaType()); }else { result = query.list(); } }else { result = query.list(); } }else{ //todo: the return type must be simple type result = dao.executeUpdate(command, map); if(null != returnType) { result = Converts.convert(result, returnType.asSimpleType().getJavaType()); } } return ApiResponse.of(result); }
public static String toTypeName(MType type) { if(type.isSimpleType()) { SwaggerType st = swaggerWriter.convertSimpleType(type.asSimpleType()); if(null == st) { throw new IllegalStateException("Unsupported type '" + type + "'"); } return st.name().toLowerCase(); } if(type.isCollectionType()) { MType elementType = type.asCollectionType().getElementType(); return "array<" + toTypeName(elementType) + ">"; } if(type.isComplexType()) { return type.asComplexType().getName(); } if(type.isTypeRef()) { return type.asTypeRef().getRefTypeName(); } if(type.isDictionaryType()) { return "map<string," + toTypeName(type.asDictionaryType().getValueType()) + ">"; } if(type.isObjectType()) { return "object"; } if(type.isVoidType()) { return ""; } throw new IllegalStateException("Unsupported type '" + type + "'"); }
writeSimpleType(context, m, w, type.asSimpleType()); return;
writeSimpleParameterType(context, m, w, p, type.asSimpleType()); return;
return validator; }else { return new TypeValidator(name, required, type.asSimpleType(), validator);
if(null != dataType) { if(dataType.isSimpleType()) { MSimpleType st = dataType.asSimpleType();