/** * TODO add a new record about nickname * * @param nickNameRequest * @param nickNameResponse * @param tnContext * @return */ public HtmlNickNameResponse addNickName( HtmlNickNameRequest nickNameRequest, HtmlNickNameResponse nickNameResponse, TnContext tnContext) { CliTransaction cli = new CliTransaction(CliConstants.TYPE_MODULE); cli.setFunctionName("addNickName"); nickNameResponse.setStatus(ExecutorResponse.STATUS_OK); long userId = nickNameRequest.getUserId(); String userName = nickNameRequest.getNickName(); nickNameResponse.setNickName(userName); UserManagementServiceStub stub = null; try { logger.debug("addNickName userId:" + userId + ",userName" + userName); // set conditions GetUserRequestDTO getUserRequest = new GetUserRequestDTO(); getUserRequest.setParam(Long.toString(userId)); getUserRequest.setParamType(UserQueryBy.USER_ID); getUserRequest.setClientName(HtmlConstants.clientName); getUserRequest.setClientVersion(HtmlConstants.clientVersion); getUserRequest.setContextString(tnContext.toContextString()); getUserRequest.setTransactionId(HtmlPoiUtil.getTrxId()); // get user stub = getServer(); GetUserResponseDTO responseDto = stub.getUser(getUserRequest); User user = responseDto.getUser(); user.setUserName(userName); // update user UpdateUserRequestDTO updateRequest = new UpdateUserRequestDTO(); updateRequest.setUser(user); updateRequest.setClientName(HtmlConstants.clientName); updateRequest.setClientVersion(HtmlConstants.clientVersion); updateRequest.setContextString(tnContext.toContextString()); updateRequest.setTransactionId(HtmlPoiUtil.getTrxId()); UserManagementResponseDTO updateResponse = stub.updateUser(updateRequest); } catch (Exception e) { logger.error(e); e.printStackTrace(); cli.setStatus(e); cli.setState(CliConstants.STATUS_FAIL); } finally { cli.complete(); WebServiceUtils.cleanupStub(stub); } return nickNameResponse; }
/** * TODO add a new record about nickname * * @param nickNameRequest * @param nickNameResponse * @param tnContext * @return */ public HtmlNickNameResponse checkAndaddNickName( HtmlNickNameRequest nickNameRequest, HtmlNickNameResponse nickNameResponse, TnContext tnContext) { CliTransaction cli = new CliTransaction(CliConstants.TYPE_MODULE); cli.setFunctionName("checkAndaddNickName"); nickNameResponse.setStatus(ExecutorResponse.STATUS_OK); UserManagementServiceStub stub = null; try { String userName = nickNameRequest.getNickName(); // set conditions IsUniqueUsernameRequestDTO isUniqueRequest = new IsUniqueUsernameRequestDTO(); isUniqueRequest.setUserName(userName); isUniqueRequest.setClientName(HtmlConstants.clientName); isUniqueRequest.setClientVersion(HtmlConstants.clientVersion); isUniqueRequest.setContextString(tnContext.toContextString()); isUniqueRequest.setTransactionId(HtmlPoiUtil.getTrxId()); // check NickName stub = getServer(); IsUniqueUsernameResponseDTO isUniqueResponse = stub.isUniqueUsername(isUniqueRequest); nickNameResponse.setNickName(userName); if (isUniqueResponse != null) { boolean isUnique = isUniqueResponse.getUnique(); logger.debug("checkNickName userName:"******",isUnique" + isUnique); cli.addData("data", "checkNickName userName:"******",isUnique" + isUnique); if (isUnique) { // the nick name is unique nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_UNIQUE_NICKNAME); long userId = nickNameRequest.getUserId(); logger.debug("addNickName userId:" + userId + ",userName" + userName); // set conditions GetUserRequestDTO getUserRequest = new GetUserRequestDTO(); getUserRequest.setParam(Long.toString(userId)); getUserRequest.setParamType(UserQueryBy.USER_ID); getUserRequest.setClientName(HtmlConstants.clientName); getUserRequest.setClientVersion(HtmlConstants.clientVersion); getUserRequest.setContextString(tnContext.toContextString()); getUserRequest.setTransactionId(HtmlPoiUtil.getTrxId()); // get user GetUserResponseDTO responseDto = stub.getUser(getUserRequest); User user = responseDto.getUser(); if (user != null) { user.setUserName(userName); // update user UpdateUserRequestDTO updateRequest = new UpdateUserRequestDTO(); updateRequest.setUser(user); updateRequest.setClientName(HtmlConstants.clientName); updateRequest.setClientVersion(HtmlConstants.clientVersion); updateRequest.setContextString(tnContext.toContextString()); updateRequest.setTransactionId(HtmlPoiUtil.getTrxId()); UserManagementResponseDTO updateResponse = stub.updateUser(updateRequest); } } else { // the nick name has exist nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_NOT_UNIQUE_NICKNAME); } } else { nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_UNIQUE_NICKNAME); } } catch (Exception e) { logger.error(e); e.printStackTrace(); cli.setStatus(e); cli.setState(CliConstants.STATUS_FAIL); } finally { cli.complete(); WebServiceUtils.cleanupStub(stub); } return nickNameResponse; }