コード例 #1
0
 private boolean validateReq(PinCodeReq pinCodeReq) {
   if (pinCodeReq != null
       && pinCodeReq.getPincode() != null
       && !pinCodeReq.getPincode().isEmpty()
       && CommonUtils.isNumber(pinCodeReq.getPincode())) {
     return true;
   }
   return false;
 }
コード例 #2
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;
  }