Example #1
0
  /* (non-Javadoc)
   * @see com.nebulent.vectura.services.resources.v1.AccountResource#createAccountRide(java.lang.String, nebulent.schema.software.vectura._1.Ride)
   */
  @Override
  public Ride createAccountRide(String accountId, Ride ride) {
    if (StringUtils.isBlank(accountId)) {
      throw new BadRequestException(
          new StatusResponse(false, "Account ID is a required field.", null));
    }

    ride.setAccountId(accountId);
    com.nebulent.vectura.data.model.mongodb.Ride mongoRide = DomainUtils.toRide(ride);
    mongoRide = getMongoRepository().getRideRepository().save(mongoRide);
    ride = DomainUtils.toRide(mongoRide);

    // Create pick-up location.
    Place place = new Place();
    place.setAddress(ride.getDropOffAddress());
    Place dropoffPlace = createAccountPlace(accountId, place);
    if (dropoffPlace != null) {
      ride.setDropOffAddress(dropoffPlace.getAddress());
    }

    // Create drop-off location.
    place = new Place();
    place.setAddress(ride.getPickupAddress());
    Place pickupPlace = createAccountPlace(accountId, place);
    if (pickupPlace != null) {
      ride.setPickupAddress(pickupPlace.getAddress());
    }

    return ride;
  }
Example #2
0
  @Override
  public Patient addAccountPatient(String accountId, Patient patient) {
    if (StringUtils.isBlank(accountId)) {
      throw new BadRequestException(
          new StatusResponse(false, "Account ID is a required field.", null));
    }

    com.nebulent.vectura.data.model.mongodb.core.Patient dbPatient = DomainUtils.toPatient(patient);
    getMongoRepository().addAccountPatient(accountId, dbPatient);
    return DomainUtils.toPatient(dbPatient);
  }
Example #3
0
  /* (non-Javadoc)
   * @see com.nebulent.vectura.services.resources.v1.AccountResource#addAccountVehicle(java.lang.String, nebulent.schema.software.vectura._1.Vehicle)
   */
  @Override
  public Vehicle addAccountVehicle(String accountId, Vehicle vehicle) {
    if (StringUtils.isBlank(accountId)) {
      throw new BadRequestException(
          new StatusResponse(false, "Account ID is a required field.", null));
    }

    com.nebulent.vectura.data.model.mongodb.core.Vehicle dbVehicle = DomainUtils.toVehicle(vehicle);
    getMongoRepository().addAccountVehicle(accountId, dbVehicle);
    return DomainUtils.toVehicleType(dbVehicle);
  }
Example #4
0
  /* (non-Javadoc)
   * @see com.nebulent.vectura.services.resources.v1.AccountResource#addAccountUser(java.lang.String, nebulent.schema.software.vectura._1.User)
   */
  @Override
  public User addAccountUser(String accountId, User user) {
    if (StringUtils.isBlank(accountId)) {
      throw new BadRequestException(
          new StatusResponse(false, "Account ID is a required field.", null));
    }

    com.nebulent.vectura.data.model.mongodb.core.User dbUser = DomainUtils.toUser(user);
    getMongoRepository().addAccountUser(accountId, dbUser);
    return DomainUtils.toUser(dbUser);
  }
Example #5
0
  @Override
  public PhoneInfo addAccountPhone(String accountId, PhoneInfo phone) {
    if (StringUtils.isBlank(accountId)) {
      throw new BadRequestException(
          new StatusResponse(false, "Account ID is a required field.", null));
    }

    com.nebulent.vectura.data.model.mongodb.core.PhoneInfo dbPhone = DomainUtils.toPhone(phone);
    getMongoRepository().addAccountPhone(accountId, dbPhone);
    return DomainUtils.toPhone(dbPhone);
  }
Example #6
0
  @Override
  public ContactType addAccountContact(String accountId, ContactType contact) {
    if (StringUtils.isBlank(accountId)) {
      throw new BadRequestException(
          new StatusResponse(false, "Account ID is a required field.", null));
    }

    Contact dbContact = DomainUtils.toContact(contact);
    getMongoRepository().addAccountContact(accountId, dbContact);
    return DomainUtils.toContact(dbContact);
  }
Example #7
0
  @Override
  public AddressInfo addAccountAddress(String accountId, AddressInfo address) {
    if (StringUtils.isBlank(accountId)) {
      throw new BadRequestException(
          new StatusResponse(false, "Account ID is a required field.", null));
    }

    com.nebulent.vectura.data.model.mongodb.core.AddressInfo dbAddress =
        DomainUtils.toAddress(address);
    getMongoRepository().addAccountAddress(accountId, dbAddress);
    return DomainUtils.toAddress(dbAddress);
  }
Example #8
0
  /* (non-Javadoc)
   * @see com.nebulent.vectura.services.resources.v1.AccountResource#createAccountPlace(java.lang.String, nebulent.schema.software.vectura._1.Place)
   */
  @Override
  public Place createAccountPlace(String accountId, Place placeType) {
    if (StringUtils.isBlank(accountId)) {
      throw new BadRequestException(
          new StatusResponse(false, "Account ID is a required field.", null));
    }

    placeType.setAccountId(accountId);
    com.nebulent.vectura.data.model.mongodb.Place location = DomainUtils.toLocation(placeType);
    location.setAccountUuid(accountId);

    Map<AddressComponent, String> parsedAddr =
        AddressParser.parseAddress(location.getAddress().toSingleLine());
    String normalizedAddress = AddressStandardizer.toSingleLine(parsedAddr);
    int addressHash = new HashCodeBuilder().append(normalizedAddress).toHashCode();

    if (addressHash != 0) {
      System.out.println(
          "Trying to find by address hash:"
              + addressHash
              + " and "
              + location.getAddress().toString());
      com.nebulent.vectura.data.model.mongodb.Place placeByHash =
          getMongoRepository().findPlaceByAccountUuidAndAddressHash(accountId, addressHash);
      if (placeByHash == null) {
        AddressInfo addressType = mapService.getLocationByAddress(location.getAddress().toString());
        if (addressType != null) {
          com.nebulent.vectura.data.model.mongodb.core.AddressInfo addressInfo =
              DomainUtils.toAddress(addressType);
          if (logger.isDebugEnabled()) {
            logger.debug("Adding location with address:" + addressInfo);
          }
          if (addressInfo != null && StringUtils.isNotBlank(addressInfo.getAddressLine1())) {
            location.setAddress(addressInfo);
            location.getAddress().setHash(addressHash);
            location.setLocation(location.getAddress().getLocation());
            location = getMongoRepository().getPlaceRepository().save(location);
          }
        }
      } else {
        System.out.println(
            "Found by address hash:" + addressHash + " and " + placeByHash.toString());

        location = placeByHash;
      }
    }

    return DomainUtils.toLocation(location);
  }
Example #9
0
  /* (non-Javadoc)
   * @see com.nebulent.vectura.services.resources.v1.AccountResource#searchAccountPlaces(java.lang.String, java.lang.String)
   */
  @Override
  public List<Place> searchAccountPlaces(String accountId, String addressHash) {
    if (StringUtils.isBlank(accountId)) {
      throw new BadRequestException(
          new StatusResponse(false, "Account ID is a required field.", null));
    }

    List<com.nebulent.vectura.data.model.mongodb.Place> locations =
        getMongoRepository().getPlaceRepository().findByAccountUuid(accountId);
    return DomainUtils.toLocations(locations);
  }
Example #10
0
  @Override
  public Run findRun(String id) {
    if (StringUtils.isBlank(id)) {
      throw new BadRequestException(new StatusResponse(false, "Run ID is a required field.", null));
    }

    com.nebulent.vectura.data.model.mongodb.Run run =
        getMongoRepository().getRunRepository().findOne(id);
    if (run != null) {
      return DomainUtils.toRun(run);
    }
    throw new NotFoundException(new StatusResponse(false, "Run not found by id:", id));
  }
Example #11
0
  @Override
  public Place findLocation(String id) {
    if (StringUtils.isBlank(id)) {
      throw new BadRequestException(
          new StatusResponse(false, "Location ID is a required field.", null));
    }

    com.nebulent.vectura.data.model.mongodb.Place location =
        getMongoRepository().getPlaceRepository().findOne(id);
    if (location != null) {
      return DomainUtils.toLocation(location);
    }
    throw new NotFoundException(new StatusResponse(false, "Location not found by id:", id));
  }
Example #12
0
  @Override
  public Account findAccount(String accountId) {
    if (StringUtils.isBlank(accountId)) {
      throw new BadRequestException(
          new StatusResponse(false, "Account ID is a required field.", null));
    }

    com.nebulent.vectura.data.model.mongodb.Account account =
        getMongoRepository().getAccountRepository().findOne(accountId);
    if (account != null) {
      return DomainUtils.toAccount(account);
    }
    throw new NotFoundException(new StatusResponse(false, "Account not found by id:", accountId));
  }
Example #13
0
  /* (non-Javadoc)
   * @see com.nebulent.vectura.services.resources.v1.AccountResource#findAccountRidesByDate(java.lang.String, java.lang.String)
   */
  @Override
  public List<Ride> findAccountRidesByDate(String accountId, String dateAsString) {
    if (StringUtils.isBlank(accountId)) {
      throw new BadRequestException(
          new StatusResponse(false, "Account ID is a required field.", null));
    }
    if (StringUtils.isBlank(dateAsString)) {
      throw new BadRequestException(new StatusResponse(false, "Date is a required field.", null));
    }

    List<com.nebulent.vectura.data.model.mongodb.Ride> rides =
        getMongoRepository()
            .getRideRepository()
            .findByAccountUuidAndRideDateAsStringOrderByApptOnAsc(accountId, dateAsString);
    return DomainUtils.toRides(rides);
  }