/** * @TODO check nickname if exist * * @param nickNameRequest * @param nickNameResponse * @param tnContext * @return */ public HtmlNickNameResponse checkNickName( HtmlNickNameRequest nickNameRequest, HtmlNickNameResponse nickNameResponse, TnContext tnContext) { CliTransaction cli = new CliTransaction(CliConstants.TYPE_MODULE); cli.setFunctionName("checkNickName"); String nickNameStr = nickNameRequest.getNickName(); nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_UNIQUE_NICKNAME); nickNameResponse.setStatus(ExecutorResponse.STATUS_OK); UserManagementServiceStub stub = null; try { // set conditions IsUniqueUsernameRequestDTO isUniqueRequest = new IsUniqueUsernameRequestDTO(); isUniqueRequest.setUserName(nickNameStr); 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(nickNameStr); 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); } else { // the nick name has exist nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_NOT_UNIQUE_NICKNAME); } } } catch (Exception e) { // TODO Auto-generated catch block 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; }