SEARCH-2833 Add field for association Qname in NodeResource and ChildAssociationResource (#678)

This commit is contained in:
Davide
2021-08-26 09:59:06 +02:00
committed by GitHub
parent 279ff3a0d8
commit a8a06f4b1f
8 changed files with 64 additions and 14 deletions

View File

@@ -53,7 +53,7 @@
<dependency.activiti.version>5.23.0</dependency.activiti.version> <dependency.activiti.version>5.23.0</dependency.activiti.version>
<dependency.alfresco-transform-model.version>1.4.0</dependency.alfresco-transform-model.version> <dependency.alfresco-transform-model.version>1.4.0</dependency.alfresco-transform-model.version>
<dependency.alfresco-greenmail.version>6.2</dependency.alfresco-greenmail.version> <dependency.alfresco-greenmail.version>6.2</dependency.alfresco-greenmail.version>
<dependency.acs-event-model.version>0.0.12</dependency.acs-event-model.version> <dependency.acs-event-model.version>0.0.13</dependency.acs-event-model.version>
<dependency.spring.version>5.3.9</dependency.spring.version> <dependency.spring.version>5.3.9</dependency.spring.version>
<dependency.antlr.version>3.5.2</dependency.antlr.version> <dependency.antlr.version>3.5.2</dependency.antlr.version>

View File

@@ -27,7 +27,6 @@ package org.alfresco.repo.event2;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Deque; import java.util.Deque;
import org.alfresco.repo.event.v1.model.ChildAssociationResource; import org.alfresco.repo.event.v1.model.ChildAssociationResource;
import org.alfresco.repo.event.v1.model.DataAttributes; import org.alfresco.repo.event.v1.model.DataAttributes;
import org.alfresco.repo.event.v1.model.EventData; import org.alfresco.repo.event.v1.model.EventData;
@@ -117,8 +116,9 @@ public class ChildAssociationEventConsolidator implements ChildAssociationEventS
{ {
String parentId = childAssociationRef.getParentRef().getId(); String parentId = childAssociationRef.getParentRef().getId();
String childId = childAssociationRef.getChildRef().getId(); String childId = childAssociationRef.getChildRef().getId();
String assocQName = helper.getQNamePrefixString(childAssociationRef.getQName());
String assocType = helper.getQNamePrefixString(childAssociationRef.getTypeQName()); String assocType = helper.getQNamePrefixString(childAssociationRef.getTypeQName());
return new ChildAssociationResource(parentId, childId, assocType); return new ChildAssociationResource(parentId, childId, assocType, assocQName);
} }
/** /**

View File

@@ -46,6 +46,7 @@ import org.alfresco.repo.event2.filter.NodePropertyFilter;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.MLText; import org.alfresco.service.cmr.repository.MLText;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
@@ -148,6 +149,7 @@ public class NodeResourceHelper implements InitializingBean
.setModifiedByUser(getUserInfo((String) properties.get(ContentModel.PROP_MODIFIER), mapUserCache)) .setModifiedByUser(getUserInfo((String) properties.get(ContentModel.PROP_MODIFIER), mapUserCache))
.setModifiedAt(getZonedDateTime((Date)properties.get(ContentModel.PROP_MODIFIED))) .setModifiedAt(getZonedDateTime((Date)properties.get(ContentModel.PROP_MODIFIED)))
.setContent(getContentInfo(properties)) .setContent(getContentInfo(properties))
.setPrimaryAssocQName(getPrimaryAssocQName(nodeRef))
.setPrimaryHierarchy(PathUtil.getNodeIdsInReverse(path, false)) .setPrimaryHierarchy(PathUtil.getNodeIdsInReverse(path, false))
.setProperties(mapToNodeProperties(properties)) .setProperties(mapToNodeProperties(properties))
.setAspectNames(getMappedAspects(nodeRef)); .setAspectNames(getMappedAspects(nodeRef));
@@ -158,6 +160,23 @@ public class NodeResourceHelper implements InitializingBean
return dictionaryService.isSubClass(className, ofClassQName); return dictionaryService.isSubClass(className, ofClassQName);
} }
private String getPrimaryAssocQName(NodeRef nodeRef)
{
String result = null;
try
{
ChildAssociationRef primaryParent = nodeService.getPrimaryParent(nodeRef);
if(primaryParent != null && primaryParent.getQName() != null)
{
result = primaryParent.getQName().getPrefixedQName(namespaceService).getPrefixString();
}
} catch (NamespaceException namespaceException)
{
LOGGER.error("Cannot return a valid primary association QName: " + namespaceException.getMessage());
}
return result;
}
private UserInfo getUserInfo(String userName, Map<String, UserInfo> mapUserCache) private UserInfo getUserInfo(String userName, Map<String, UserInfo> mapUserCache)
{ {
UserInfo userInfo = mapUserCache.get(userName); UserInfo userInfo = mapUserCache.get(userName);

View File

@@ -36,6 +36,7 @@ import java.util.List;
import javax.jms.ConnectionFactory; import javax.jms.ConnectionFactory;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.dictionary.NamespaceDAO;
import org.alfresco.repo.event.v1.model.ChildAssociationResource; import org.alfresco.repo.event.v1.model.ChildAssociationResource;
import org.alfresco.repo.event.v1.model.DataAttributes; import org.alfresco.repo.event.v1.model.DataAttributes;
import org.alfresco.repo.event.v1.model.EventType; import org.alfresco.repo.event.v1.model.EventType;
@@ -114,6 +115,9 @@ public abstract class AbstractContextAwareRepoEvent extends BaseSpringTest
@Qualifier("eventGeneratorQueue") @Qualifier("eventGeneratorQueue")
protected EventGeneratorQueue eventQueue; protected EventGeneratorQueue eventQueue;
@Autowired
private NamespaceDAO namespaceDAO;
protected NodeRef rootNodeRef; protected NodeRef rootNodeRef;
@BeforeClass @BeforeClass
@@ -152,9 +156,19 @@ public abstract class AbstractContextAwareRepoEvent extends BaseSpringTest
return nodeService.getRootNode(storeRef); return nodeService.getRootNode(storeRef);
}); });
initTestNamespacePrefixMapping();
flushSpuriousEvents(); flushSpuriousEvents();
} }
protected void initTestNamespacePrefixMapping() {
if(namespaceDAO.getNamespaceURI("ce") == null)
{
namespaceDAO.addURI(TEST_NAMESPACE);
namespaceDAO.addPrefix("ce", TEST_NAMESPACE);
}
}
/* /*
* When running with an empty database some events related to the creation may * When running with an empty database some events related to the creation may
* creep up here making the test fails. After attempting several other * creep up here making the test fails. After attempting several other
@@ -207,11 +221,16 @@ public abstract class AbstractContextAwareRepoEvent extends BaseSpringTest
} }
protected NodeRef createNode(QName contentType, PropertyMap propertyMap) protected NodeRef createNode(QName contentType, PropertyMap propertyMap)
{
return createNode(contentType, GUID.generate(), propertyMap);
}
protected NodeRef createNode(QName contentType, String localName, PropertyMap propertyMap)
{ {
return retryingTransactionHelper.doInTransaction(() -> nodeService.createNode( return retryingTransactionHelper.doInTransaction(() -> nodeService.createNode(
rootNodeRef, rootNodeRef,
ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN,
QName.createQName(TEST_NAMESPACE, GUID.generate()), QName.createQName(TEST_NAMESPACE, localName),
contentType, contentType,
propertyMap).getChildRef()); propertyMap).getChildRef());
} }

View File

@@ -50,6 +50,7 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
@Test @Test
public void testAddChildAssociation() public void testAddChildAssociation()
{ {
String assocLocalName = GUID.generate();
final NodeRef parentNodeRef = createNode(ContentModel.TYPE_FOLDER); final NodeRef parentNodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef childNodeRef = createNode(ContentModel.TYPE_CONTENT); final NodeRef childNodeRef = createNode(ContentModel.TYPE_CONTENT);
@@ -64,11 +65,11 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
resultRepoEvent.getType()); resultRepoEvent.getType());
retryingTransactionHelper.doInTransaction(() -> retryingTransactionHelper.doInTransaction(() ->
nodeService.addChild( nodeService.addChild(
parentNodeRef, parentNodeRef,
childNodeRef, childNodeRef,
ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS,
QName.createQName(TEST_NAMESPACE, GUID.generate()))); QName.createQName(TEST_NAMESPACE, assocLocalName)));
List<ChildAssociationRef> childAssociationRefs = retryingTransactionHelper.doInTransaction(() -> List<ChildAssociationRef> childAssociationRefs = retryingTransactionHelper.doInTransaction(() ->
nodeService.getChildAssocs(parentNodeRef)); nodeService.getChildAssocs(parentNodeRef));
@@ -101,6 +102,7 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
assertEquals("Wrong parent", parentNodeRef.getId(), childAssociationResource.getParent().getId()); assertEquals("Wrong parent", parentNodeRef.getId(), childAssociationResource.getParent().getId());
assertEquals("Wrong child", childNodeRef.getId(), childAssociationResource.getChild().getId()); assertEquals("Wrong child", childNodeRef.getId(), childAssociationResource.getChild().getId());
assertEquals("Wrong assoc type", "cm:contains", childAssociationResource.getAssocType()); assertEquals("Wrong assoc type", "cm:contains", childAssociationResource.getAssocType());
assertEquals("Wrong assoc name", "ce:" + assocLocalName, childAssociationResource.getAssocQName());
} }
@Test @Test

View File

@@ -53,16 +53,17 @@ public class CreateRepoEventIT extends AbstractContextAwareRepoEvent
@Autowired @Autowired
private NodeDAO nodeDAO; private NodeDAO nodeDAO;
@Test @Test
public void testCreateEvent() public void testCreateEvent()
{ {
// Create a node without content // Create a node without content
final String name = "TestFile-" + System.currentTimeMillis() + ".txt"; final String name = "TestFile-" + System.currentTimeMillis() + ".txt";
String localName = GUID.generate();
PropertyMap propertyMap = new PropertyMap(); PropertyMap propertyMap = new PropertyMap();
propertyMap.put(ContentModel.PROP_TITLE, "test title"); propertyMap.put(ContentModel.PROP_TITLE, "test title");
propertyMap.put(ContentModel.PROP_NAME, name); propertyMap.put(ContentModel.PROP_NAME, name);
final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT, propertyMap); final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT, localName, propertyMap);
final RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1); final RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1);
// Repo event attributes // Repo event attributes
@@ -103,6 +104,7 @@ public class CreateRepoEventIT extends AbstractContextAwareRepoEvent
assertEquals("Wrong node modifier display name.", "Administrator", assertEquals("Wrong node modifier display name.", "Administrator",
nodeResource.getModifiedByUser().getDisplayName()); nodeResource.getModifiedByUser().getDisplayName());
assertNotNull("Missing modifiedAt property.", nodeResource.getModifiedAt()); assertNotNull("Missing modifiedAt property.", nodeResource.getModifiedAt());
assertEquals("Wrong primaryAssocQName prefix.", "ce:" + localName, nodeResource.getPrimaryAssocQName());
} }
@Test @Test

View File

@@ -45,9 +45,10 @@ public class DeleteRepoEventIT extends AbstractContextAwareRepoEvent
@Test @Test
public void testDeleteContent() public void testDeleteContent()
{ {
String localName = GUID.generate();
PropertyMap propertyMap = new PropertyMap(); PropertyMap propertyMap = new PropertyMap();
propertyMap.put(ContentModel.PROP_TITLE, "test title"); propertyMap.put(ContentModel.PROP_TITLE, "test title");
NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT, propertyMap); NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT, localName, propertyMap);
NodeResource createdResource = getNodeResource(1); NodeResource createdResource = getNodeResource(1);
@@ -64,6 +65,7 @@ public class DeleteRepoEventIT extends AbstractContextAwareRepoEvent
assertEquals("Repo event type:", EventType.NODE_DELETED.getType(), resultRepoEvent.getType()); assertEquals("Repo event type:", EventType.NODE_DELETED.getType(), resultRepoEvent.getType());
assertEquals(createdResource.getId(), getNodeResource(resultRepoEvent).getId()); assertEquals(createdResource.getId(), getNodeResource(resultRepoEvent).getId());
assertEquals("Wrong primaryAssocQName prefix.", "ce:" + localName, createdResource.getPrimaryAssocQName());
// There should be no resourceBefore // There should be no resourceBefore
EventData<NodeResource> eventData = getEventData(resultRepoEvent); EventData<NodeResource> eventData = getEventData(resultRepoEvent);

View File

@@ -33,7 +33,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.dictionary.M2Model; import org.alfresco.repo.dictionary.M2Model;
@@ -59,6 +58,7 @@ import org.junit.Test;
*/ */
public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
{ {
@Test @Test
public void testUpdateNodeResourceContent() public void testUpdateNodeResourceContent()
{ {
@@ -138,6 +138,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
assertNull(resourceBefore.getProperties()); assertNull(resourceBefore.getProperties());
assertNull(resourceBefore.getAspectNames()); assertNull(resourceBefore.getAspectNames());
assertNull(resourceBefore.getPrimaryHierarchy()); assertNull(resourceBefore.getPrimaryHierarchy());
assertNull(resourceBefore.getPrimaryAssocQName());
} }
@Test @Test
@@ -198,6 +199,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
assertNull(resourceBefore.getProperties()); assertNull(resourceBefore.getProperties());
assertNull(resourceBefore.getAspectNames()); assertNull(resourceBefore.getAspectNames());
assertNull(resourceBefore.getPrimaryHierarchy()); assertNull(resourceBefore.getPrimaryHierarchy());
assertNull(resourceBefore.getPrimaryAssocQName());
} }
@Test @Test
@@ -274,6 +276,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
assertNull(resourceBefore.getProperties()); assertNull(resourceBefore.getProperties());
assertNull(resourceBefore.getAspectNames()); assertNull(resourceBefore.getAspectNames());
assertNull(resourceBefore.getPrimaryHierarchy()); assertNull(resourceBefore.getPrimaryHierarchy());
assertNull(resourceBefore.getPrimaryAssocQName());
} }
@Test @Test
@@ -539,6 +542,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
assertNull(resourceBefore.getProperties()); assertNull(resourceBefore.getProperties());
assertNull(resourceBefore.getAspectNames()); assertNull(resourceBefore.getAspectNames());
assertNull(resourceBefore.getPrimaryHierarchy()); assertNull(resourceBefore.getPrimaryHierarchy());
assertNull(resourceBefore.getPrimaryAssocQName());
} }
@Test @Test
@@ -574,6 +578,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
NodeResource nodeResource = getNodeResource(resultRepoEvent); NodeResource nodeResource = getNodeResource(resultRepoEvent);
assertEquals("Incorrect node type was found", "cm:dictionaryModel", nodeResource.getNodeType()); assertEquals("Incorrect node type was found", "cm:dictionaryModel", nodeResource.getNodeType());
initTestNamespacePrefixMapping();
final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT); final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
// old node's type // old node's type
assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef)); assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));
@@ -613,7 +618,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
assertNull(resourceBefore.getProperties()); assertNull(resourceBefore.getProperties());
assertNull(resourceBefore.getAspectNames()); assertNull(resourceBefore.getAspectNames());
assertNull(resourceBefore.getPrimaryHierarchy()); assertNull(resourceBefore.getPrimaryHierarchy());
assertNull(resourceBefore.getPrimaryAssocQName());
} }
@Test @Test
@@ -660,6 +665,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
assertNull(resourceBefore.getProperties()); assertNull(resourceBefore.getProperties());
assertNull(resourceBefore.getAspectNames()); assertNull(resourceBefore.getAspectNames());
assertNull(resourceBefore.getPrimaryHierarchy()); assertNull(resourceBefore.getPrimaryHierarchy());
assertNull(resourceBefore.getPrimaryAssocQName());
} }
@Test @Test