diff --git a/nuxeo-ai-core/src/main/java/org/nuxeo/ai/auto/AutoServiceImpl.java b/nuxeo-ai-core/src/main/java/org/nuxeo/ai/auto/AutoServiceImpl.java index 6a3deff12..1d78c3072 100644 --- a/nuxeo-ai-core/src/main/java/org/nuxeo/ai/auto/AutoServiceImpl.java +++ b/nuxeo-ai-core/src/main/java/org/nuxeo/ai/auto/AutoServiceImpl.java @@ -129,6 +129,7 @@ protected void calculateAutoFill(SuggestionMetadataWrapper docMetadata, String x Framework.getService(DocMetadataService.class) .updateAuto(docMetadata.getDoc(), AUTO_FILLED, xpath, null, comment); + docMetadata.addAutoFilled(xpath); } else if (alreadyAutofilled) { // We autofilled but now the value didn't autofill so lets reset it Framework.getService(DocMetadataService.class) diff --git a/nuxeo-ai-core/src/main/java/org/nuxeo/ai/metadata/SuggestionMetadataWrapper.java b/nuxeo-ai-core/src/main/java/org/nuxeo/ai/metadata/SuggestionMetadataWrapper.java index 26782e624..6f6dae1ad 100644 --- a/nuxeo-ai-core/src/main/java/org/nuxeo/ai/metadata/SuggestionMetadataWrapper.java +++ b/nuxeo-ai-core/src/main/java/org/nuxeo/ai/metadata/SuggestionMetadataWrapper.java @@ -158,6 +158,15 @@ public Set getAutoFilled() { return autoFilled; } + /** + * Update auto filled values for sequential operations + * @param xpath {@link DocumentModel} property path + * @return {@link Boolean#TRUE} if successfully added + */ + public boolean addAutoFilled(String xpath) { + return autoFilled.add(xpath); + } + public Set getAutoCorrected() { return autoCorrected; } diff --git a/nuxeo-ai-core/src/test/java/org/nuxeo/ai/enrichment/TestAutoServices.java b/nuxeo-ai-core/src/test/java/org/nuxeo/ai/enrichment/TestAutoServices.java index 35bf6e383..640d0c144 100644 --- a/nuxeo-ai-core/src/test/java/org/nuxeo/ai/enrichment/TestAutoServices.java +++ b/nuxeo-ai-core/src/test/java/org/nuxeo/ai/enrichment/TestAutoServices.java @@ -28,6 +28,7 @@ import static org.nuxeo.ai.AIConstants.AUTO_HISTORY; import static org.nuxeo.ai.AIConstants.ENRICHMENT_ITEMS; import static org.nuxeo.ai.AIConstants.ENRICHMENT_SCHEMA_NAME; +import static org.nuxeo.ai.auto.AutoService.AUTO_ACTION.ALL; import static org.nuxeo.ai.auto.AutoService.AUTO_ACTION.CORRECT; import static org.nuxeo.ai.auto.AutoService.AUTO_ACTION.FILL; import static org.nuxeo.ai.enrichment.TestDocMetadataService.setupTestEnrichmentMetadata; @@ -53,6 +54,7 @@ import org.nuxeo.ecm.core.api.Blob; import org.nuxeo.ecm.core.api.CoreSession; import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.event.EventServiceAdmin; import org.nuxeo.ecm.platform.test.PlatformFeature; import org.nuxeo.runtime.test.runner.Deploy; import org.nuxeo.runtime.test.runner.Features; @@ -60,8 +62,8 @@ import org.nuxeo.runtime.test.runner.TransactionalFeature; @RunWith(FeaturesRunner.class) -@Features({EnrichmentTestFeature.class, AutomationFeature.class, PlatformFeature.class}) -@Deploy({"org.nuxeo.ai.ai-core", "org.nuxeo.ai.ai-core:OSGI-INF/auto-config-test.xml"}) +@Features({ EnrichmentTestFeature.class, AutomationFeature.class, PlatformFeature.class }) +@Deploy({ "org.nuxeo.ai.ai-core" }) public class TestAutoServices { @Inject @@ -82,10 +84,41 @@ public class TestAutoServices { @Inject protected TransactionalFeature txFeature; + @Inject + protected EventServiceAdmin esa; + + @Test + @Deploy("org.nuxeo.ai.ai-core:OSGI-INF/core-types-test.xml") + @Deploy("org.nuxeo.ai.ai-core:OSGI-INF/auto-config-test2.xml") + public void testAutoAll() { + DocumentModel testDoc = session.createDocumentModel("/", "My Auto Doc", "MultiFile"); + testDoc = session.createDocument(testDoc); + session.saveDocument(testDoc); + txFeature.nextTransaction(); + + esa.setListenerEnabledFlag("enrichedDirtyProp", false); + esa.setListenerEnabledFlag("enrichmentModified", false); + try { + EnrichmentMetadata suggestionMetadata = setupTestEnrichmentMetadata(testDoc); + testDoc = docMetadataService.saveEnrichment(session, suggestionMetadata); + session.saveDocument(testDoc); + txFeature.nextTransaction(); + + autoService.calculateProperties(testDoc, ALL); + testDoc = session.saveDocument(testDoc); + + assertThat((String[]) testDoc.getPropertyValue("complexTest:testList")).hasSize(3); + } finally { + esa.setListenerEnabledFlag("enrichedDirtyProp", true); + esa.setListenerEnabledFlag("enrichmentModified", true); + } + + } + @Test @Deploy("org.nuxeo.ai.ai-core:OSGI-INF/core-types-test.xml") + @Deploy("org.nuxeo.ai.ai-core:OSGI-INF/auto-config-test.xml") public void testAutofill() { - assertNotNull(docMetadataService); DocumentModel testDoc = session.createDocumentModel("/", "My Auto Doc", "MultiFile"); testDoc = session.createDocument(testDoc); session.saveDocument(testDoc); @@ -93,7 +126,8 @@ public void testAutofill() { for (String schema : testDoc.getSchemas()) { for (Map.Entry entry : testDoc.getProperties(schema).entrySet()) { - System.out.println(schema + " prop " + entry.getKey() + " is list " + testDoc.getPropertyObject(schema, entry.getKey()).isList()); + System.out.println(schema + " prop " + entry.getKey() + " is list " + + testDoc.getPropertyObject(schema, entry.getKey()).isList()); } } @@ -160,6 +194,7 @@ public void testAutofill() { } @Test + @Deploy("org.nuxeo.ai.ai-core:OSGI-INF/auto-config-test.xml") public void testAutoCorrect() { String formatText = "something"; DocumentModel testDoc = session.createDocumentModel("/", "My Auto Corrected Doc", "File"); @@ -201,6 +236,7 @@ public void testAutoCorrect() { } @Test + @Deploy("org.nuxeo.ai.ai-core:OSGI-INF/auto-config-test.xml") public void testAutoHistory() { DocumentModel testDoc = session.createDocumentModel("/", "My Auto History Doc", "File"); testDoc = session.createDocument(testDoc); @@ -231,6 +267,7 @@ public void testAutoHistory() { } @Test + @Deploy("org.nuxeo.ai.ai-core:OSGI-INF/auto-config-test.xml") public void testUpdateAutoHistory() { String comment = "No Comment"; DocumentModel testDoc = session.createDocumentModel("/", "My Auto Hist Doc", "File"); @@ -268,16 +305,15 @@ public void testUpdateAutoHistory() { // We have updated dc:title and dc:format twice but we should have only the 2 latest entries in the history. assertEquals(2, history.size()); - assertEquals("NOT_OLD", history.stream() - .filter(h -> "dc:title".equals(h.getProperty())) - .findFirst().get().getPreviousValue()); - assertEquals("OLDISH", history.stream() - .filter(h -> "dc:format".equals(h.getProperty())) - .findFirst().get().getPreviousValue()); + assertEquals("NOT_OLD", + history.stream().filter(h -> "dc:title".equals(h.getProperty())).findFirst().get().getPreviousValue()); + assertEquals("OLDISH", + history.stream().filter(h -> "dc:format".equals(h.getProperty())).findFirst().get().getPreviousValue()); } @Test + @Deploy("org.nuxeo.ai.ai-core:OSGI-INF/auto-config-test.xml") public void testAutoOperation() throws OperationException { // Setup doc with suggestions DocumentModel testDoc = session.createDocumentModel("/", "My Auto Op Doc", "File"); @@ -300,6 +336,7 @@ public void testAutoOperation() throws OperationException { } @Test + @Deploy("org.nuxeo.ai.ai-core:OSGI-INF/auto-config-test.xml") public void testhasValue() { DocumentModel testDoc = session.createDocumentModel("/", "My Auto Value Doc", "File"); testDoc = session.createDocument(testDoc); @@ -319,7 +356,7 @@ public void testhasValue() { wrapper = new SuggestionMetadataWrapper(testDoc); assertFalse("Must allow empty strings[]", wrapper.hasHumanValue("dc:subjects")); - testDoc.setPropertyValue("dc:subjects", new String[]{"sciences", "art/cinema"}); + testDoc.setPropertyValue("dc:subjects", new String[] { "sciences", "art/cinema" }); wrapper = new SuggestionMetadataWrapper(testDoc); assertTrue(wrapper.hasHumanValue("dc:subjects")); diff --git a/nuxeo-ai-core/src/test/resources/OSGI-INF/auto-config-test2.xml b/nuxeo-ai-core/src/test/resources/OSGI-INF/auto-config-test2.xml new file mode 100644 index 000000000..a93d38377 --- /dev/null +++ b/nuxeo-ai-core/src/test/resources/OSGI-INF/auto-config-test2.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + diff --git a/nuxeo-ai-model/src/test/java/org/nuxeo/ai/bulk/BulkEnrichmentTest.java b/nuxeo-ai-model/src/test/java/org/nuxeo/ai/bulk/BulkEnrichmentTest.java index b9d22d53a..8cec99041 100644 --- a/nuxeo-ai-model/src/test/java/org/nuxeo/ai/bulk/BulkEnrichmentTest.java +++ b/nuxeo-ai-model/src/test/java/org/nuxeo/ai/bulk/BulkEnrichmentTest.java @@ -39,6 +39,7 @@ import java.util.Arrays; import java.util.List; import java.util.Set; + import javax.inject.Inject; import org.junit.Rule;