Skip to content

Commit d9484ee

Browse files
authored
feat(permanentid): replace sha256 by md5(30)+sha1(30) (#17)
https://coveord.atlassian.net/browse/CDX-784
1 parent 5bab9be commit d9484ee

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/main/java/com/coveo/pushapiclient/DocumentBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ private void validateReservedMetadataKeyNames(String key) {
360360

361361
private void generatePermanentId() {
362362
if (this.document.permanentId == null) {
363-
this.document.permanentId = DigestUtils.sha256Hex(this.document.uri);
363+
String md5 = DigestUtils.md5Hex(this.document.uri);
364+
String sha1 = DigestUtils.sha1Hex(this.document.uri);
365+
this.document.permanentId = md5.substring(0, 30) + sha1.substring(0, 30);
364366
}
365367
}
366368
}

src/test/java/com/coveo/pushapiclient/DocumentBuilderTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ public void testWithPermanentId() {
132132

133133
@Test
134134
public void testWithPermanentIdGeneration() {
135-
assertTrue(
135+
docBuilder = new DocumentBuilder("https://foo.com", "bar");
136+
assertEquals(
136137
"permanentId should be generated automatically if not set",
137-
docBuilder.marshalJsonObject().get("permanentId").getAsString().length() > 0
138+
"aa2e0510b66edff7f05e2b30d4f1b3a4b5481c06b69f41751c54675c5afb",
139+
docBuilder.marshalJsonObject().get("permanentId").getAsString()
138140
);
139141
}
140142

@@ -373,4 +375,4 @@ public void marshal() {
373375
);
374376
}
375377

376-
}
378+
}

0 commit comments

Comments
 (0)