-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalise email address value before adding to index table (#1550)
* Normalise email address value before adding to index table * If parsing fails, log a warning and return the original value (this should not happen normally but we can investigate further). * Remove duplicated code
- Loading branch information
Showing
4 changed files
with
411 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ons/src/main/java/net/ripe/db/whois/common/dao/jdbc/index/IndexWithEmailAddressValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.ripe.db.whois.common.dao.jdbc.index; | ||
|
||
import net.ripe.db.whois.common.dao.RpslObjectInfo; | ||
import net.ripe.db.whois.common.rpsl.AttributeParser; | ||
import net.ripe.db.whois.common.rpsl.AttributeType; | ||
import net.ripe.db.whois.common.rpsl.RpslObject; | ||
import net.ripe.db.whois.common.rpsl.attrs.AttributeParseException; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
class IndexWithEmailAddressValue extends IndexWithValue { | ||
|
||
private static final AttributeParser.EmailParser EMAIL_PARSER = new AttributeParser.EmailParser(); | ||
|
||
public IndexWithEmailAddressValue(final AttributeType attributeType, final String lookupTableName, final String lookupColumnName) { | ||
super(attributeType, lookupTableName, lookupColumnName); | ||
} | ||
|
||
@Override | ||
public int addToIndex(final JdbcTemplate jdbcTemplate, final RpslObjectInfo objectInfo, final RpslObject object, final String value) { | ||
return super.addToIndex(jdbcTemplate, objectInfo, object, normaliseEmailAddress(value)); | ||
} | ||
|
||
protected static String normaliseEmailAddress(final String emailAddress) { | ||
try { | ||
return EMAIL_PARSER.parse(emailAddress).getAddress(); | ||
} catch (AttributeParseException e) { | ||
return emailAddress; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../main/java/net/ripe/db/whois/common/dao/jdbc/index/IndexWithEmailAddressValueAndType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package net.ripe.db.whois.common.dao.jdbc.index; | ||
|
||
import net.ripe.db.whois.common.dao.RpslObjectInfo; | ||
import net.ripe.db.whois.common.rpsl.AttributeType; | ||
import net.ripe.db.whois.common.rpsl.RpslObject; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
class IndexWithEmailAddressValueAndType extends IndexWithValueAndType { | ||
|
||
public IndexWithEmailAddressValueAndType(final AttributeType attributeType, final String lookupTableName, final String lookupColumnName) { | ||
super(attributeType, lookupTableName, lookupColumnName); | ||
} | ||
|
||
@Override | ||
public int addToIndex(JdbcTemplate jdbcTemplate, RpslObjectInfo objectInfo, RpslObject object, String value) { | ||
return super.addToIndex(jdbcTemplate, objectInfo, object, IndexWithEmailAddressValue.normaliseEmailAddress(value)); | ||
} | ||
} |
Oops, something went wrong.