Skip to content

Commit

Permalink
SDK-580: Refactor AddressTransformer following review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bucky-boy committed Oct 15, 2018
1 parent 2d6d42b commit 2a1ea3b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ static final AddressTransformer newInstance() {
return new AddressTransformer();
}

public Attribute<String> transform(Attribute<?> structuredAddress) {
Attribute<String> transform(Attribute<?> structuredPostalAddress) {
Attribute<String> transformedAddress = null;
try {
Attribute<Map<?, ?>> address = (Attribute<Map<?, ?>>) structuredAddress;
if (address.getValue() != null) {
Object formattedAddress = address.getValue().get(HumanProfileAttributes.Keys.FORMATTED_ADDRESS);
if (structuredPostalAddress.getValue() != null) {
final Map<?, ?> structuredAddressValue = (Map<?, ?>) structuredPostalAddress.getValue();
final Object formattedAddress = structuredAddressValue.get(HumanProfileAttributes.Keys.FORMATTED_ADDRESS);
if (formattedAddress != null) {
transformedAddress = new SimpleAttribute(HumanProfileAttributes.POSTAL_ADDRESS,
String.valueOf(formattedAddress),
structuredAddress.getSources(),
structuredAddress.getVerifiers(),
structuredAddress.getAnchors());
structuredPostalAddress.getSources(),
structuredPostalAddress.getVerifiers(),
structuredPostalAddress.getAnchors());
}
}
} catch (Exception e) {
LOG.warn("Failed to transform attribute '{}' in place of missing '{}' due to '{}'", structuredAddress.getName(),
LOG.warn("Failed to transform attribute '{}' in place of missing '{}' due to '{}'", structuredPostalAddress.getName(),
HumanProfileAttributes.POSTAL_ADDRESS, e.getMessage());
}
return transformedAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ private List<Attribute<?>> parseAttributes(AttributeListProto.AttributeList mess

private void ensurePostalAddress(List<Attribute<?>> attributes) {
if (findAttribute(POSTAL_ADDRESS, attributes) == null) {
Attribute<?> structuredAddress = findAttribute(STRUCTURED_POSTAL_ADDRESS, attributes);
if (structuredAddress != null) {
Attribute<String> transformedAddress = addressTransformer.transform(structuredAddress);
Attribute<?> structuredPostalAddress = findAttribute(STRUCTURED_POSTAL_ADDRESS, attributes);
if (structuredPostalAddress != null) {
Attribute<String> transformedAddress = addressTransformer.transform(structuredPostalAddress);
if (transformedAddress != null) {
LOG.debug("Substituting '{}' in place of missing '{}'", STRUCTURED_POSTAL_ADDRESS, POSTAL_ADDRESS);
attributes.add(transformedAddress);
Expand Down

0 comments on commit 2a1ea3b

Please sign in to comment.