mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
SEARCH-2378: Update the whole PARENT list when updating a Document
Cherry picked from 84bb8db
This commit is contained in:
+96
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Search Services E2E Test
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.test.search.functional.searchServices.search;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.search.SearchResponse;
|
||||
import org.alfresco.test.search.functional.AbstractE2EFunctionalTest;
|
||||
import org.alfresco.utility.data.DataGroup;
|
||||
import org.alfresco.utility.model.GroupModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Test class tests PARENT field is including all the PARENT Nodes
|
||||
* Created for SEARCH-2378
|
||||
*/
|
||||
public class SearchParentField extends AbstractE2EFunctionalTest
|
||||
{
|
||||
@Autowired
|
||||
protected DataGroup dataGroup;
|
||||
|
||||
List<GroupModel> groups;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void dataPreparation()
|
||||
{
|
||||
|
||||
groups = new ArrayList<>();
|
||||
groups.add(dataGroup.createRandomGroup());
|
||||
groups.add(dataGroup.createRandomGroup());
|
||||
|
||||
dataGroup.addListOfUsersToGroup(groups.get(0), testUser);
|
||||
dataGroup.addListOfUsersToGroup(groups.get(1), testUser);
|
||||
|
||||
waitForIndexing(
|
||||
"TYPE:'cm:authorityContainer' AND cm:authorityName:'GROUP_" + groups.get(1).getGroupIdentifier() + "'",
|
||||
true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test users in groups can be found using PARENT expressions.
|
||||
*/
|
||||
@Test(priority = 1)
|
||||
public void testSearchParentForPerson() throws Exception
|
||||
{
|
||||
|
||||
for (GroupModel group : groups)
|
||||
{
|
||||
|
||||
// Find groupId to be used in the PARENT expression
|
||||
String queryGroup = "TYPE:'cm:authorityContainer' AND cm:authorityName:'GROUP_" + group.getGroupIdentifier()
|
||||
+ "'";
|
||||
SearchResponse response = queryAsUser(dataUser.getAdminUser(), queryGroup);
|
||||
String groupId = response.getEntries().get(0).getModel().getId();
|
||||
|
||||
// Find the user assigned as member of this group with PARENT clause
|
||||
String queryParentGroup = "(TYPE:'cm:person' OR TYPE:'cm:authorityContainer') AND PARENT:'workspace://SpacesStore/"
|
||||
+ groupId + "'";
|
||||
|
||||
response = queryAsUser(dataUser.getAdminUser(), queryParentGroup);
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
Assert.assertEquals(response.getPagination().getCount(), 1, "Expecting 1 user (" + testUser.getUsername()
|
||||
+ ") as member of this group (" + group.getGroupIdentifier() + ")");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+30
-26
@@ -1716,7 +1716,7 @@ public class SolrInformationServer implements InformationServer
|
||||
.orElse(false);
|
||||
|
||||
addDocCmd.solrDoc = isIndexed
|
||||
? populateWithMetadata(basicDocument(nodeMetaData, DOC_TYPE_NODE, PartialSolrInputDocument::new), nodeMetaData)
|
||||
? populateWithMetadata(basicDocument(nodeMetaData, DOC_TYPE_NODE, PartialSolrInputDocument::new), nodeMetaData, nmdp)
|
||||
: basicDocument(nodeMetaData, DOC_TYPE_UNINDEXED_NODE, SolrInputDocument::new);
|
||||
processor.processAdd(addDocCmd);
|
||||
}
|
||||
@@ -2073,7 +2073,7 @@ public class SolrInformationServer implements InformationServer
|
||||
|
||||
addDocCmd.solrDoc =
|
||||
populateWithMetadata(basicDocument(nodeMetaData, DOC_TYPE_NODE, PartialSolrInputDocument::new),
|
||||
nodeMetaData);
|
||||
nodeMetaData, nmdp);
|
||||
processor.processAdd(addDocCmd);
|
||||
|
||||
this.trackerStats.addNodeTime(System.nanoTime() - start);
|
||||
@@ -2097,9 +2097,9 @@ public class SolrInformationServer implements InformationServer
|
||||
}
|
||||
}
|
||||
|
||||
private SolrInputDocument populateWithMetadata(SolrInputDocument document, NodeMetaData metadata)
|
||||
private SolrInputDocument populateWithMetadata(SolrInputDocument document, NodeMetaData metadata, NodeMetaDataParameters nmdp)
|
||||
{
|
||||
populateFields(metadata, document);
|
||||
populateFields(metadata, document, nmdp);
|
||||
|
||||
LOGGER.debug("Document size (fields) after getting fields from node {} metadata: {}", metadata.getId(), document.size());
|
||||
|
||||
@@ -2114,7 +2114,7 @@ public class SolrInformationServer implements InformationServer
|
||||
return document;
|
||||
}
|
||||
|
||||
private void populateFields(NodeMetaData metadata, SolrInputDocument doc)
|
||||
private void populateFields(NodeMetaData metadata, SolrInputDocument doc, NodeMetaDataParameters nmdp)
|
||||
{
|
||||
doc.setField(FIELD_TYPE, metadata.getType().toString());
|
||||
notNullOrEmpty(metadata.getAspects())
|
||||
@@ -2165,31 +2165,35 @@ public class SolrInformationServer implements InformationServer
|
||||
StringBuilder qNameBuffer = new StringBuilder();
|
||||
StringBuilder assocTypeQNameBuffer = new StringBuilder();
|
||||
|
||||
notNullOrEmpty(metadata.getParentAssocs())
|
||||
.forEach(childAssocRef -> {
|
||||
if (qNameBuffer.length() > 0)
|
||||
{
|
||||
qNameBuffer.append(";/");
|
||||
assocTypeQNameBuffer.append(";/");
|
||||
}
|
||||
qNameBuffer.append(ISO9075.getXPathName(childAssocRef.getQName()));
|
||||
assocTypeQNameBuffer.append(ISO9075.getXPathName(childAssocRef.getTypeQName()));
|
||||
doc.setField(FIELD_PARENT, childAssocRef.getParentRef().toString());
|
||||
|
||||
if (childAssocRef.isPrimary())
|
||||
{
|
||||
if(doc.getField(FIELD_PRIMARYPARENT) == null)
|
||||
if (nmdp.isIncludeParentAssociations())
|
||||
{
|
||||
doc.removeField(FIELD_PARENT);
|
||||
notNullOrEmpty(metadata.getParentAssocs())
|
||||
.forEach(childAssocRef -> {
|
||||
if (qNameBuffer.length() > 0)
|
||||
{
|
||||
doc.setField(FIELD_PRIMARYPARENT, childAssocRef.getParentRef().toString());
|
||||
doc.setField(FIELD_PRIMARYASSOCTYPEQNAME, ISO9075.getXPathName(childAssocRef.getTypeQName()));
|
||||
doc.setField(FIELD_PRIMARYASSOCQNAME, ISO9075.getXPathName(childAssocRef.getQName()));
|
||||
qNameBuffer.append(";/");
|
||||
assocTypeQNameBuffer.append(";/");
|
||||
}
|
||||
else
|
||||
qNameBuffer.append(ISO9075.getXPathName(childAssocRef.getQName()));
|
||||
assocTypeQNameBuffer.append(ISO9075.getXPathName(childAssocRef.getTypeQName()));
|
||||
doc.addField(FIELD_PARENT, childAssocRef.getParentRef().toString());
|
||||
|
||||
if (childAssocRef.isPrimary())
|
||||
{
|
||||
LOGGER.warning("Duplicate primary parent for node id {}", metadata.getId());
|
||||
if(doc.getField(FIELD_PRIMARYPARENT) == null)
|
||||
{
|
||||
doc.setField(FIELD_PRIMARYPARENT, childAssocRef.getParentRef().toString());
|
||||
doc.setField(FIELD_PRIMARYASSOCTYPEQNAME, ISO9075.getXPathName(childAssocRef.getTypeQName()));
|
||||
doc.setField(FIELD_PRIMARYASSOCQNAME, ISO9075.getXPathName(childAssocRef.getQName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.warning("Duplicate primary parent for node id {}", metadata.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
ofNullable(metadata.getParentAssocs()).ifPresent(parents -> {
|
||||
doc.addField(FIELD_ASSOCTYPEQNAME, assocTypeQNameBuffer.toString());
|
||||
|
||||
Reference in New Issue
Block a user