示例#1
0
  protected boolean checkAccess(UserRequest userRequest, ServiceCodes code) throws TxtException {
    User user = new UserDAO().findUserByMobileNo(userRequest.getMobileNo());
    if (user == null) {
      throw new TxtException(TxtExceptionCodes.ERROR.USER_NOT_FOUND);
    }

    boolean isAccess = false;
    for (String serviceCode : user.getLstServices()) {
      if (code.name().equalsIgnoreCase(serviceCode)) {
        isAccess = true;
        break;
      }
    }

    if (!isAccess) {
      throw new TxtException(TxtExceptionCodes.ERROR.SERVICE_NOT_REGISTER);
    }
    return isAccess;
  }
  private void doPublishBid(UserRequest userRequest, UserRespose userRespose) throws TxtException {

    // Fetch params
    String description = getParameter(userRequest, 0);
    String startTime = getParameter(userRequest, 1);
    String endTime = getParameter(userRequest, 2);
    String bidType = getParameter(userRequest, 3);

    // User user = new UserDAO().findUserByMobileNo(userRequest.getMobileNo());

    // Validate
    // if(!(user.getIsAdminUser()!=null &&
    // user.getIsAdminUser().equalsIgnoreCase(TxtAppConstant.YES))){
    // throw new TxtException(TxtExceptionCodes.ERROR.NOT_AN_ADMIN_USER);
    // }
    if (!ValidateUtil.validateDate(startTime, DateUtil.DATE_FORMAT_DD_MM_YY_HH_MM)) {
      throw new TxtException(TxtExceptionCodes.ERROR.INVALID_DATE_FORMAT);
    }
    if (!ValidateUtil.validateDate(endTime, DateUtil.DATE_FORMAT_DD_MM_YY_HH_MM)) {
      throw new TxtException(TxtExceptionCodes.ERROR.INVALID_DATE_FORMAT);
    }
    if (!ValidateUtil.validateGreaterThanCurrent(startTime, DateUtil.DATE_FORMAT_DD_MM_YY_HH_MM)) {
      throw new TxtException(TxtExceptionCodes.ERROR.TIME_ALREADY_PASSED);
    }
    if (!ValidateUtil.validateGreaterThanCurrent(endTime, DateUtil.DATE_FORMAT_DD_MM_YY_HH_MM)) {
      throw new TxtException(TxtExceptionCodes.ERROR.TIME_ALREADY_PASSED);
    }
    if (!ValidateUtil.validateGreater(startTime, endTime, DateUtil.DATE_FORMAT_DD_MM_YY_HH_MM)) {
      throw new TxtException(TxtExceptionCodes.ERROR.STARTDATE_LESSTHAN_ENDDATE);
    }

    // Store bid
    Bid bid = new Bid();
    bid.setDescription(description);
    bid.setStartTime(startTime);
    bid.setEndTime(endTime);
    bid.setBidType(bidType);
    if (bid.getBidType().equalsIgnoreCase(BidTypes.LOWER.getCode())) {
      bid.setCurrentBid(Long.MAX_VALUE);
    } else if (bid.getBidType().equalsIgnoreCase(BidTypes.HIGHER.getCode())) {
      bid.setCurrentBid(0L);
    }
    bid.setIsFinished(TxtAppConstant.NO);

    bid = new BidDAO().saveBid(bid);
    List<User> lstUser = new UserDAO().findUsersByServiceCode(ServiceCodes.BID.getCode());

    // Schedule Bid
    TaskSchedular taskSchedular = TaskSchedular.getInstance();
    ScheduleTask scheduleTask = taskSchedular.getScheduleTask(bid.getStartTime());
    scheduleTask.setCode(TaskCodes.START_BID.name());
    scheduleTask.setTaskType(TaskTypes.ONCE.name());
    scheduleTask.setTaskData(bid.getBidNo() + "");
    taskSchedular.addTask(scheduleTask);

    taskSchedular = TaskSchedular.getInstance();
    ScheduleTask endSchTask = taskSchedular.getScheduleTask(bid.getEndTime());
    endSchTask.setCode(TaskCodes.END_BID.name());
    endSchTask.setTaskType(TaskTypes.ONCE.name());
    endSchTask.setTaskData(bid.getBidNo() + "");
    taskSchedular.addTask(endSchTask);

    // Publish bid
    String bidMessage = getMessage(TxtResourceConstants.PUBLISH_BID);
    bidMessage = replaceDynTags(bidMessage, TxtResourceConstants.BID_NO, bid.getBidNo() + "");
    bidMessage = replaceDynTags(bidMessage, TxtResourceConstants.BID_DESC, bid.getDescription());
    bidMessage =
        replaceDynTags(bidMessage, TxtResourceConstants.BID_START_TIME, bid.getStartTime());
    bidMessage = replaceDynTags(bidMessage, TxtResourceConstants.BID_END_TIME, bid.getEndTime());
    bidMessage = replaceDynTags(bidMessage, TxtResourceConstants.BID_TYPE, bid.getBidType());

    for (User bidUser : lstUser) {
      TxtWebUtil.pushMessage(bidUser.getMobileNo(), bidMessage);
    }

    // User response
    String bidMessageResponse = getMessage(TxtResourceConstants.PUBLISH_BID_RESPONSE);
    bidMessageResponse =
        replaceDynTags(bidMessageResponse, TxtResourceConstants.BID_NO, bid.getBidNo() + "");
    bidMessageResponse =
        replaceDynTags(bidMessageResponse, TxtResourceConstants.BID_START_TIME, bid.getStartTime());
    bidMessageResponse =
        replaceDynTags(bidMessageResponse, TxtResourceConstants.BID_END_TIME, bid.getEndTime());

    userRespose.setMessage(bidMessageResponse);
  }