diff --git a/src/main/java/com/coveo/pushapiclient/DocumentBuilder.java b/src/main/java/com/coveo/pushapiclient/DocumentBuilder.java index 2b62053b..a95fe6a1 100644 --- a/src/main/java/com/coveo/pushapiclient/DocumentBuilder.java +++ b/src/main/java/com/coveo/pushapiclient/DocumentBuilder.java @@ -360,7 +360,9 @@ private void validateReservedMetadataKeyNames(String key) { private void generatePermanentId() { if (this.document.permanentId == null) { - this.document.permanentId = DigestUtils.sha256Hex(this.document.uri); + String md5 = DigestUtils.md5Hex(this.document.uri); + String sha1 = DigestUtils.sha1Hex(this.document.uri); + this.document.permanentId = md5.substring(0, 30) + sha1.substring(0, 30); } } } diff --git a/src/test/java/com/coveo/pushapiclient/DocumentBuilderTest.java b/src/test/java/com/coveo/pushapiclient/DocumentBuilderTest.java index 6a5dcdac..43f3cf61 100644 --- a/src/test/java/com/coveo/pushapiclient/DocumentBuilderTest.java +++ b/src/test/java/com/coveo/pushapiclient/DocumentBuilderTest.java @@ -132,9 +132,11 @@ public void testWithPermanentId() { @Test public void testWithPermanentIdGeneration() { - assertTrue( + docBuilder = new DocumentBuilder("https://foo.com", "bar"); + assertEquals( "permanentId should be generated automatically if not set", - docBuilder.marshalJsonObject().get("permanentId").getAsString().length() > 0 + "aa2e0510b66edff7f05e2b30d4f1b3a4b5481c06b69f41751c54675c5afb", + docBuilder.marshalJsonObject().get("permanentId").getAsString() ); } @@ -373,4 +375,4 @@ public void marshal() { ); } -} \ No newline at end of file +}