Пример #1
0
  @Override
  @Transactional(readOnly = false)
  public ResponseWrapper<PinCodeResp> getPinCodeData(
      RequestWrapper<PinCodeReq> requestWrapper, Long trxNumber) {
    MsgHeader msgHeader = requestWrapper.getMsgHeader();
    PinCodeReq pinCodeReq = requestWrapper.getData();
    PinCodeResp pinCodeResp = new PinCodeResp();
    ResponseWrapper<PinCodeResp> responseWrapper = new ResponseWrapper<PinCodeResp>();
    DeviceFPmsgHeader deviceFPmsgHeader = requestWrapper.getDeviceFPmsgHeader();
    boolean validToken = false;
    Long customerId = null;
    Boolean guestLoginFlag = false;
    boolean validateGuestFlag = false;
    MsgHeaderResp msgHeaderResp = null;
    if (validateHeader(msgHeader) && validateReq(pinCodeReq)) {
      msgHeaderResp = getMessageResponse(msgHeader, trxNumber);
      TransactionInfoEntity transactionInfoEntity =
          getTransactionEntity(msgHeader, deviceFPmsgHeader, Constants.API_PIN_CODE_GET, trxNumber);
      String loginId = msgHeader.getLoginId();
      if (!validateConsumer(msgHeader)) {
        Error errorMsg = getErrorMsg(Constants.ERR_CODE_APPLICATION_ACCESS);
        CommonUtils.setErrorInRespose(msgHeaderResp, errorMsg);
      } else {
        if (!Constants.GUEST_LOGIN_FLAG_Y.equalsIgnoreCase(msgHeader.getGuestLoginFlag())) {
          validToken = validateAuthToken(msgHeader, msgHeaderResp);
        }
        // TODO Validating CustomerID not require for time being as
        // basic API
        // Can add it if required
        RcmdEngineResponseWrapper<PinCodeWebResp> engineResponse = null;
        RcmdEngineRequestWrapper<PinCodeWebReq> engineRequestWrapper =
            new RcmdEngineRequestWrapper<PinCodeWebReq>();
        String pinCode = pinCodeReq.getPincode();
        PinCodeWebReq pinCodeWebReq = new PinCodeWebReq();
        pinCodeWebReq.setPincode(Integer.parseInt(pinCode));
        RcmndEngineMsgRequest engineMsgRequest = new RcmndEngineMsgRequest();
        engineMsgRequest.setChannelType(msgHeader.getChannelType());
        engineMsgRequest.setGuestLoginFlag(msgHeader.getGuestLoginFlag());
        engineMsgRequest.setTransactionId(trxNumber);
        engineMsgRequest.setLoginId(msgHeader.getLoginId());
        engineRequestWrapper.setMsgHeader(engineMsgRequest);
        engineRequestWrapper.setDeviceFPmsgHeader(deviceFPmsgHeader);
        engineRequestWrapper.setData(pinCodeWebReq);
        try {
          engineResponse =
              DreamRecommendationEngine.pinCode(
                  recommendationUrl, pincodeResource, engineRequestWrapper, trxNumber);
        } catch (IOException e) {
          logger.error(Constants.EXP_MSG_JSON_TO_RECC + trxNumber);
          Error error = getErrorMsg(Constants.ERR_CODE_INVALID_PINCODE);
          msgHeaderResp = CommonUtils.setErrorInRespose(msgHeaderResp, error);
        }
        if (engineResponse != null) {
          PinCodeWebResp pinCodeWebResp = engineResponse.getData();
          pinCodeResp.setDistrict(pinCodeWebResp.getCity());
          pinCodeResp.setState(pinCodeWebResp.getState());
        } else {
          Error error = getErrorMsg(Constants.ERR_CODE_INVALID_PINCODE);
          msgHeaderResp = CommonUtils.setErrorInRespose(msgHeaderResp, error);
        }

        baseDao.saveTransactionInfo(transactionInfoEntity);
      }
      if (msgHeader != null && msgHeaderResp.getHostStatus() == null) {
        msgHeaderResp.setHostStatus(Constants.HOST_STATUS_SUCCESS);
      }
      responseWrapper.setMessage(msgHeaderResp);
      responseWrapper.setData(pinCodeResp);
    } else {
      Error error = getErrorMsg(Constants.ERR_CODE_BAD_REQUEST);
      responseWrapper = CommonUtils.malformedResp(pinCodeResp, trxNumber, error);
    }
    return responseWrapper;
  }
Пример #2
0
  @Transactional(readOnly = false)
  @Override
  public ResponseWrapper<SendOtpResp> sendOtp(
      RequestWrapper<SendOtpReq> requestWrapper, Long trxNumber) {
    MsgHeader msgHeader = requestWrapper.getMsgHeader();
    SendOtpReq sendOtpReq = requestWrapper.getData();
    SendOtpResp sendOtpResp = new SendOtpResp();
    ResponseWrapper<SendOtpResp> responseWrapper = new ResponseWrapper<SendOtpResp>();
    DeviceFPmsgHeader deviceFPmsgHeader = requestWrapper.getDeviceFPmsgHeader();
    Long customerId = null;
    MsgHeaderResp msgHeaderResp = null;
    Boolean guestLoginFlag = false;
    boolean validateGuestFlag = false;
    Boolean successFlag = false;
    if (validateHeader(msgHeader) && validateReq(sendOtpReq)) {
      msgHeaderResp = getMessageResponse(msgHeader, trxNumber);
      TransactionInfoEntity transactionInfoEntity =
          getTransactionEntity(msgHeader, deviceFPmsgHeader, Constants.API_SEND_OTP, trxNumber);
      String loginId = msgHeader.getLoginId();
      if (!validateConsumer(msgHeader)) {
        Error errorMsg = getErrorMsg(Constants.ERR_CODE_APPLICATION_ACCESS);
        CommonUtils.setErrorInRespose(msgHeaderResp, errorMsg);
      } else {
        sendOtpResp.setOtpFor(sendOtpReq.getOtpFor());
        AppUserDetailsEntity appUserDetailsEntity = null;
        if (Constants.GUEST_LOGIN_FLAG_Y.equalsIgnoreCase(msgHeader.getGuestLoginFlag())) {
          appUserDetailsEntity = validateGuestLogin(msgHeader);
          guestLoginFlag = true;
          if (appUserDetailsEntity == null) {
            transactionInfoEntity.setLoginId(loginId);
            msgHeaderResp.setLoginId(loginId);
            Error errorMsg = getErrorMsg(Constants.ERR_INVALID_GUEST);
            msgHeaderResp = CommonUtils.setErrorInRespose(msgHeaderResp, errorMsg);
          } else {
            transactionInfoEntity.setLoginId(loginId);
            msgHeaderResp.setLoginId(loginId);
            validateGuestFlag = true;
            // Verify Email to be done using Guest Login
            if (Constants.OTP_VERIFY_EMAIL.equalsIgnoreCase(sendOtpReq.getOtpFor())) {
              CustomerCredEntity customerCredEntity =
                  baseDao.getCustomerId(sendOtpReq.getEmailId());
              if (customerCredEntity != null) {
                List<Error_> error_s = sendOtpResp.getError();
                Error_ error_ = new Error_();
                error_.setErrorCode(Constants.ERR_BODY_USER_ID_ALREADY_EXIST.toString());
                ErrorMsgEntity errorMsg =
                    baseDao.getErrorMsg(Constants.ERR_BODY_USER_ID_ALREADY_EXIST);
                error_.setErrorMessage(errorMsg.getDesc());
                error_s.add(error_);
              } else {
                successFlag =
                    sendOtp(
                        trxNumber, loginId, customerId, guestLoginFlag, sendOtpReq, sendOtpResp);
              }
            } else {
              Error errorMsg = getErrorMsg(Constants.ERR_CODE_GUEST_LOGIN_NOT_ALLWED);
              CommonUtils.setErrorInRespose(msgHeaderResp, errorMsg);
            }
          }
        } else {
          guestLoginFlag = false;
          // Non Verify Email for Non-Guest
          if (!Constants.OTP_VERIFY_EMAIL.equalsIgnoreCase(sendOtpReq.getOtpFor())) {
            CustomerCredEntity customerCredEntity = baseDao.getCustomerId(loginId);
            if (customerCredEntity != null && loginId.equalsIgnoreCase(sendOtpReq.getEmailId())) {
              if (Constants.CUST_ACCOUNT_ACTIVE.equalsIgnoreCase(
                  customerCredEntity.getAccountStatus())) {
                successFlag =
                    sendOtp(
                        trxNumber,
                        loginId,
                        customerCredEntity.getCustomerId(),
                        guestLoginFlag,
                        sendOtpReq,
                        sendOtpResp);
              } else {
                // If account is locked then send message
                List<Error_> error_s = sendOtpResp.getError();
                Error_ error_ = new Error_();
                error_.setErrorCode(Constants.ERR_BODY_ACCNT_LOCKED.toString());
                ErrorMsgEntity errorMsg = baseDao.getErrorMsg(Constants.ERR_BODY_ACCNT_LOCKED);
                error_.setErrorMessage(errorMsg.getDesc());
                error_s.add(error_);
              }

            } else {
              // If invalid account
              List<Error_> error_s = sendOtpResp.getError();
              Error_ error_ = new Error_();
              error_.setErrorCode(Constants.ERR_INVALID_EMAIL_ID.toString());
              ErrorMsgEntity errorMsg = baseDao.getErrorMsg(Constants.ERR_INVALID_EMAIL_ID);
              error_.setErrorMessage(errorMsg.getDesc());
              error_s.add(error_);
            }

          } else {
            Error errorMsg = getErrorMsg(Constants.ERR_CODE_INTERNAL_ERROR);
            msgHeaderResp = CommonUtils.setErrorInRespose(msgHeaderResp, errorMsg);
          }
        }
        baseDao.saveTransactionInfo(transactionInfoEntity);
      }
      if (msgHeader != null && msgHeaderResp.getHostStatus() == null) {
        msgHeaderResp.setHostStatus(Constants.HOST_STATUS_SUCCESS);
      }
      sendOtpResp.setSuccessflag(successFlag);
      responseWrapper.setMessage(msgHeaderResp);
      responseWrapper.setData(sendOtpResp);
    } else {
      Error error = getErrorMsg(Constants.ERR_CODE_BAD_REQUEST);
      responseWrapper = CommonUtils.malformedResp(sendOtpResp, trxNumber, error);
    }
    return responseWrapper;
  }