Skip to content

Commit

Permalink
Merge pull request #901 from Alfresco/fix/SEARCH-2378_GroupMembersPARENT
Browse files Browse the repository at this point in the history
SEARCH-2378: Storing every different PARENT for a Document instead of…
  • Loading branch information
aborroy authored Aug 18, 2020
2 parents 6c01e74 + 4917232 commit 627c7b3
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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() + ")");

}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ public void indexNode(Node node, boolean overwrite) throws IOException, JSONExce
.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);
}
Expand Down Expand Up @@ -2073,7 +2073,7 @@ public void indexNodes(List<Node> nodes, boolean overwrite) throws IOException,

addDocCmd.solrDoc =
populateWithMetadata(basicDocument(nodeMetaData, DOC_TYPE_NODE, PartialSolrInputDocument::new),
nodeMetaData);
nodeMetaData, nmdp);
processor.processAdd(addDocCmd);

this.trackerStats.addNodeTime(System.nanoTime() - start);
Expand All @@ -2097,9 +2097,9 @@ public void indexNodes(List<Node> nodes, boolean overwrite) throws IOException,
}
}

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());

Expand All @@ -2114,7 +2114,7 @@ private SolrInputDocument populateWithMetadata(SolrInputDocument document, NodeM
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())
Expand Down Expand Up @@ -2165,31 +2165,35 @@ private void populateFields(NodeMetaData metadata, SolrInputDocument doc)
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());
Expand Down

0 comments on commit 627c7b3

Please sign in to comment.