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.alfresco-transform-model.version>1.4.0</dependency.alfresco-transform-model.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.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.Deque;
import org.alfresco.repo.event.v1.model.ChildAssociationResource;
import org.alfresco.repo.event.v1.model.DataAttributes;
import org.alfresco.repo.event.v1.model.EventData;
@@ -117,8 +116,9 @@ public class ChildAssociationEventConsolidator implements ChildAssociationEventS
{
String parentId = childAssociationRef.getParentRef().getId();
String childId = childAssociationRef.getChildRef().getId();
String assocQName = helper.getQNamePrefixString(childAssociationRef.getQName());
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.permissions.AccessDeniedException;
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.MLText;
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))
.setModifiedAt(getZonedDateTime((Date)properties.get(ContentModel.PROP_MODIFIED)))
.setContent(getContentInfo(properties))
.setPrimaryAssocQName(getPrimaryAssocQName(nodeRef))
.setPrimaryHierarchy(PathUtil.getNodeIdsInReverse(path, false))
.setProperties(mapToNodeProperties(properties))
.setAspectNames(getMappedAspects(nodeRef));
@@ -158,6 +160,23 @@ public class NodeResourceHelper implements InitializingBean
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)
{
UserInfo userInfo = mapUserCache.get(userName);

View File

@@ -36,6 +36,7 @@ import java.util.List;
import javax.jms.ConnectionFactory;
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.DataAttributes;
import org.alfresco.repo.event.v1.model.EventType;
@@ -114,6 +115,9 @@ public abstract class AbstractContextAwareRepoEvent extends BaseSpringTest
@Qualifier("eventGeneratorQueue")
protected EventGeneratorQueue eventQueue;
@Autowired
private NamespaceDAO namespaceDAO;
protected NodeRef rootNodeRef;
@BeforeClass
@@ -152,9 +156,19 @@ public abstract class AbstractContextAwareRepoEvent extends BaseSpringTest
return nodeService.getRootNode(storeRef);
});
initTestNamespacePrefixMapping();
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
* 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)
{
return createNode(contentType, GUID.generate(), propertyMap);
}
protected NodeRef createNode(QName contentType, String localName, PropertyMap propertyMap)
{
return retryingTransactionHelper.doInTransaction(() -> nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(TEST_NAMESPACE, GUID.generate()),
QName.createQName(TEST_NAMESPACE, localName),
contentType,
propertyMap).getChildRef());
}

View File

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

View File

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

View File

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

View File

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