Created
September 8, 2013 17:13
-
-
Save He-Pin/6486561 to your computer and use it in GitHub Desktop.
play wow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //for user service | |
| public static Result listUserDeviceWS(){ | |
| return handleGET(new DefaultGETHandler("userName") | |
| .queryHandler(new DefaultGETHandler.QueryHandler() { | |
| @Override | |
| public Result handle(final String queryValue) { | |
| final Promise<Result> resultPromise = | |
| rpcUserDeviceList(queryValue) | |
| .map(new F.Function<MDMDeviceListResponse, Result>() { | |
| @Override | |
| public Result apply(MDMDeviceListResponse mdmDeviceListResponse) throws Throwable { | |
| if (mdmDeviceListResponse != null){ | |
| ListResponseBean listResponseBean = DeviceServiceConverter.convert(mdmDeviceListResponse); | |
| return ok(listResponseBean); | |
| }else { | |
| return errorResult("mdmDeviceListResponse == null"); | |
| } | |
| } | |
| }); | |
| return async(resultPromise); | |
| } | |
| })); | |
| } | |
| private static Promise<MDMDeviceListResponse> rpcUserDeviceList(final String userNames){ | |
| final String token = token(); | |
| return deviceRpc.getDeviceList(token,userNames) | |
| .map(new F.Function<WS.Response, MDMDeviceListResponse>() { | |
| @Override | |
| public MDMDeviceListResponse apply(WS.Response response) throws Throwable { | |
| final JsonNode jsonNode = response.asJson(); | |
| if (isOK(jsonNode)) { | |
| MDMDeviceListResponse mdmDeviceListResponse = | |
| Json.fromJson(jsonNode, MDMDeviceListResponse.class); | |
| return mdmDeviceListResponse; | |
| } else { | |
| return null; | |
| } | |
| } | |
| }); | |
| } | |
| private static Promise<List<Long>> rpcUserDeviceIdsList(final String username){ | |
| return rpcUserDeviceList(username) | |
| .map(new F.Function<MDMDeviceListResponse, List<Long>>() { | |
| @Override | |
| public List<Long> apply(MDMDeviceListResponse mdmDeviceListResponse) throws Throwable { | |
| if (mdmDeviceListResponse == null){ | |
| return null; | |
| } | |
| List<Long> deviceIds = new ArrayList<Long>(); | |
| for (MdmDeviceInfoVo vo : mdmDeviceListResponse.getDevices()){ | |
| deviceIds.add(vo.getId()); | |
| } | |
| return deviceIds; | |
| } | |
| }); | |
| } | |
| public static Result listUserPolicyWS(){ | |
| final F.Function<List<Long>,Result> function | |
| = new F.Function<List<Long>, Result>() { | |
| @Override | |
| public Result apply(List<Long> longs) throws Throwable { | |
| return null; | |
| } | |
| }; | |
| return listUserDevicesItem(function); | |
| } | |
| public static Result listUserConfigWS(){ | |
| final F.Function<List<Long>,Result> function | |
| = new F.Function<List<Long>, Result>() { | |
| @Override | |
| public Result apply(List<Long> longs) throws Throwable { | |
| return null; | |
| } | |
| }; | |
| return listUserDevicesItem(function); | |
| } | |
| public static Result listUserDocWS(){ | |
| final F.Function<List<Long>,Result> function | |
| = new F.Function<List<Long>, Result>() { | |
| @Override | |
| public Result apply(List<Long> longs) throws Throwable { | |
| return null; | |
| } | |
| }; | |
| return listUserDevicesItem(function); | |
| } | |
| private static <R extends Result> Result listUserDevicesItem(final F.Function<List<Long>,R> function){ | |
| return handleGET(new DefaultGETHandler("userName") | |
| .queryHandler(new DefaultGETHandler.QueryHandler() { | |
| @Override | |
| public Result handle(final String queryValue) { | |
| final Promise<Result> resultPromise = | |
| rpcUserDeviceIdsList(queryValue) | |
| .map(new F.Function<List<Long>, Result>() { | |
| @Override | |
| public Result apply(List<Long> deviceIds) throws Throwable { | |
| if (deviceIds == null){ | |
| return errorResult("deviceIds is null"); | |
| }else { | |
| //here is an sequence call | |
| return function.apply(deviceIds); | |
| } | |
| } | |
| }); | |
| return async(resultPromise); | |
| } | |
| })); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment