Exemplo n.º 1
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);
  }
Exemplo n.º 2
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);
  }