Skip to content

Commit

Permalink
AICORE-323: updating metadata reference with autofill props
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Nechaev committed Jun 25, 2020
1 parent e7aa8a8 commit f7eba5a
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
Expand Up @@ -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)
Expand Down
Expand Up @@ -158,6 +158,15 @@ public Set<String> 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<String> getAutoCorrected() {
return autoCorrected;
}
Expand Down
Expand Up @@ -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;
Expand All @@ -53,15 +54,16 @@
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;
import org.nuxeo.runtime.test.runner.FeaturesRunner;
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
Expand All @@ -82,18 +84,50 @@ 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);
txFeature.nextTransaction();

for (String schema : testDoc.getSchemas()) {
for (Map.Entry<String, Object> 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());
}
}

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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"));

Expand Down
15 changes: 15 additions & 0 deletions nuxeo-ai-core/src/test/resources/OSGI-INF/auto-config-test2.xml
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<component name="org.nuxeo.ai.auto.another.config.test" version="1.0">

<extension target="org.nuxeo.ai.configuration.ThresholdComponent"
point="thresholdConfiguration">

<thresholdConfiguration type="MultiFile" global="0.88">
<thresholds>
<threshold xpath="dc:title" autofill="0.4" autocorrect="0.7"/>
<threshold xpath="dc:format" autocorrect="0.9"/>
<threshold xpath="complexTest:testList" autofill="0.5" autocorrect="0.55"/>
</thresholds>
</thresholdConfiguration>
</extension>
</component>
Expand Up @@ -39,6 +39,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Set;

import javax.inject.Inject;

import org.junit.Rule;
Expand Down

0 comments on commit f7eba5a

Please sign in to comment.