mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
[MNT-24807] Fix failing tests
This commit is contained in:
@@ -42,6 +42,9 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.event.v1.model.ContentInfo;
|
import org.alfresco.repo.event.v1.model.ContentInfo;
|
||||||
@@ -69,9 +72,6 @@ import org.alfresco.service.namespace.NamespaceService;
|
|||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.util.PathUtil;
|
import org.alfresco.util.PathUtil;
|
||||||
import org.alfresco.util.PropertyCheck;
|
import org.alfresco.util.PropertyCheck;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for {@link NodeResource} objects.
|
* Helper for {@link NodeResource} objects.
|
||||||
@@ -82,15 +82,15 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
{
|
{
|
||||||
private static final Log LOGGER = LogFactory.getLog(NodeResourceHelper.class);
|
private static final Log LOGGER = LogFactory.getLog(NodeResourceHelper.class);
|
||||||
|
|
||||||
protected NodeService nodeService;
|
protected NodeService nodeService;
|
||||||
protected DictionaryService dictionaryService;
|
protected DictionaryService dictionaryService;
|
||||||
protected PersonService personService;
|
protected PersonService personService;
|
||||||
protected EventFilterRegistry eventFilterRegistry;
|
protected EventFilterRegistry eventFilterRegistry;
|
||||||
protected NamespaceService namespaceService;
|
protected NamespaceService namespaceService;
|
||||||
protected PermissionService permissionService;
|
protected PermissionService permissionService;
|
||||||
protected PropertyReplacer propertyReplacer;
|
protected PropertyReplacer propertyReplacer;
|
||||||
|
|
||||||
private NodeAspectFilter nodeAspectFilter;
|
private NodeAspectFilter nodeAspectFilter;
|
||||||
private NodePropertyFilter nodePropertyFilter;
|
private NodePropertyFilter nodePropertyFilter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -127,7 +127,7 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
{
|
{
|
||||||
this.permissionService = permissionService;
|
this.permissionService = permissionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// To make IntelliJ stop complaining about unused method!
|
// To make IntelliJ stop complaining about unused method!
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void setEventFilterRegistry(EventFilterRegistry eventFilterRegistry)
|
public void setEventFilterRegistry(EventFilterRegistry eventFilterRegistry)
|
||||||
@@ -156,22 +156,22 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
Map<String, UserInfo> mapUserCache = new HashMap<>(2);
|
Map<String, UserInfo> mapUserCache = new HashMap<>(2);
|
||||||
|
|
||||||
return NodeResource.builder()
|
return NodeResource.builder()
|
||||||
.setId(nodeRef.getId())
|
.setId(nodeRef.getId())
|
||||||
.setName((String) properties.get(ContentModel.PROP_NAME))
|
.setName((String) properties.get(ContentModel.PROP_NAME))
|
||||||
.setNodeType(getQNamePrefixString(type))
|
.setNodeType(getQNamePrefixString(type))
|
||||||
.setIsFile(isSubClass(type, ContentModel.TYPE_CONTENT))
|
.setIsFile(isSubClass(type, ContentModel.TYPE_CONTENT))
|
||||||
.setIsFolder(isSubClass(type, ContentModel.TYPE_FOLDER))
|
.setIsFolder(isSubClass(type, ContentModel.TYPE_FOLDER))
|
||||||
.setCreatedByUser(getUserInfo((String) properties.get(ContentModel.PROP_CREATOR), mapUserCache))
|
.setCreatedByUser(getUserInfo((String) properties.get(ContentModel.PROP_CREATOR), mapUserCache))
|
||||||
.setCreatedAt(getZonedDateTime((Date)properties.get(ContentModel.PROP_CREATED)))
|
.setCreatedAt(getZonedDateTime((Date) properties.get(ContentModel.PROP_CREATED)))
|
||||||
.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))
|
.setPrimaryAssocQName(getPrimaryAssocQName(nodeRef))
|
||||||
.setPrimaryHierarchy(PathUtil.getNodeIdsInReverse(path, false))
|
.setPrimaryHierarchy(PathUtil.getNodeIdsInReverse(path, false))
|
||||||
.setProperties(mapToNodeProperties(properties))
|
.setProperties(mapToNodeProperties(properties))
|
||||||
.setLocalizedProperties(mapToNodeLocalizedProperties(properties))
|
.setLocalizedProperties(mapToNodeLocalizedProperties(properties))
|
||||||
.setAspectNames(getMappedAspects(nodeRef))
|
.setAspectNames(getMappedAspects(nodeRef))
|
||||||
.setSecondaryParents(getSecondaryParents(nodeRef));
|
.setSecondaryParents(getSecondaryParents(nodeRef));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSubClass(QName className, QName ofClassQName)
|
private boolean isSubClass(QName className, QName ofClassQName)
|
||||||
@@ -179,17 +179,18 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
return dictionaryService.isSubClass(className, ofClassQName);
|
return dictionaryService.isSubClass(className, ofClassQName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPrimaryAssocQName(NodeRef nodeRef)
|
private String getPrimaryAssocQName(NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
String result = null;
|
String result = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ChildAssociationRef primaryParent = nodeService.getPrimaryParent(nodeRef);
|
ChildAssociationRef primaryParent = nodeService.getPrimaryParent(nodeRef);
|
||||||
if(primaryParent != null && primaryParent.getQName() != null)
|
if (primaryParent != null && primaryParent.getQName() != null)
|
||||||
{
|
{
|
||||||
result = primaryParent.getQName().getPrefixedQName(namespaceService).getPrefixString();
|
result = primaryParent.getQName().getPrefixedQName(namespaceService).getPrefixString();
|
||||||
}
|
}
|
||||||
} catch (NamespaceException namespaceException)
|
}
|
||||||
|
catch (NamespaceException namespaceException)
|
||||||
{
|
{
|
||||||
LOGGER.error("Cannot return a valid primary association QName: " + namespaceException.getMessage());
|
LOGGER.error("Cannot return a valid primary association QName: " + namespaceException.getMessage());
|
||||||
}
|
}
|
||||||
@@ -241,7 +242,7 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
final MLText mlTextValue = (MLText) v;
|
final MLText mlTextValue = (MLText) v;
|
||||||
final HashMap<String, String> localizedValues = new HashMap<>(mlTextValue.size());
|
final HashMap<String, String> localizedValues = new HashMap<>(mlTextValue.size());
|
||||||
mlTextValue.forEach((locale, text) -> {
|
mlTextValue.forEach((locale, text) -> {
|
||||||
Serializable replacedValue = propertyReplacer.replace(k, v);
|
Serializable replacedValue = propertyReplacer.replace(k, text);
|
||||||
localizedValues.put(locale.toString(), replacedValue.toString());
|
localizedValues.put(locale.toString(), replacedValue.toString());
|
||||||
});
|
});
|
||||||
filteredProps.put(getQNamePrefixString(k), localizedValues);
|
filteredProps.put(getQNamePrefixString(k), localizedValues);
|
||||||
@@ -270,7 +271,7 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
{
|
{
|
||||||
String sysUserName = AuthenticationUtil.getSystemUserName();
|
String sysUserName = AuthenticationUtil.getSystemUserName();
|
||||||
if (userName.equals(sysUserName) || (AuthenticationUtil.isMtEnabled()
|
if (userName.equals(sysUserName) || (AuthenticationUtil.isMtEnabled()
|
||||||
&& userName.startsWith(sysUserName + "@")))
|
&& userName.startsWith(sysUserName + "@")))
|
||||||
{
|
{
|
||||||
userInfo = new UserInfo(userName, userName, "");
|
userInfo = new UserInfo(userName, userName, "");
|
||||||
}
|
}
|
||||||
@@ -317,11 +318,11 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the QName in the format prefix:local, but in the exceptional case where there is no registered prefix
|
* Returns the QName in the format prefix:local, but in the exceptional case where there is no registered prefix returns it in the form {uri}local.
|
||||||
* returns it in the form {uri}local.
|
|
||||||
*
|
*
|
||||||
* @param k QName
|
* @param k
|
||||||
* @return a String representing the QName in the format prefix:local or {uri}local.
|
* QName
|
||||||
|
* @return a String representing the QName in the format prefix:local or {uri}local.
|
||||||
*/
|
*/
|
||||||
public String getQNamePrefixString(QName k)
|
public String getQNamePrefixString(QName k)
|
||||||
{
|
{
|
||||||
@@ -353,7 +354,7 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
|
|
||||||
public QName getNodeType(NodeRef nodeRef)
|
public QName getNodeType(NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
return nodeService.getType(nodeRef);
|
return nodeService.getType(nodeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Serializable getProperty(NodeRef nodeRef, QName qName)
|
public Serializable getProperty(NodeRef nodeRef, QName qName)
|
||||||
@@ -363,13 +364,14 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
|
|
||||||
public Map<QName, Serializable> getProperties(NodeRef nodeRef)
|
public Map<QName, Serializable> getProperties(NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
//We need to have full MLText properties here. This is why we are marking the current thread as MLAware
|
// We need to have full MLText properties here. This is why we are marking the current thread as MLAware
|
||||||
final boolean toRestore = MLPropertyInterceptor.isMLAware();
|
final boolean toRestore = MLPropertyInterceptor.isMLAware();
|
||||||
MLPropertyInterceptor.setMLAware(true);
|
MLPropertyInterceptor.setMLAware(true);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return nodeService.getProperties(nodeRef);
|
return nodeService.getProperties(nodeRef);
|
||||||
} finally
|
}
|
||||||
|
finally
|
||||||
{
|
{
|
||||||
MLPropertyInterceptor.setMLAware(toRestore);
|
MLPropertyInterceptor.setMLAware(toRestore);
|
||||||
}
|
}
|
||||||
@@ -388,7 +390,7 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, Map<String, String>> getLocalizedPropertiesBefore(Map<String, Map<String, String>> locPropsBefore,
|
static Map<String, Map<String, String>> getLocalizedPropertiesBefore(Map<String, Map<String, String>> locPropsBefore,
|
||||||
Map<String, Map<String, String>> locPropsAfter)
|
Map<String, Map<String, String>> locPropsAfter)
|
||||||
{
|
{
|
||||||
final Map<String, Map<String, String>> result = new HashMap<>(locPropsBefore.size());
|
final Map<String, Map<String, String>> result = new HashMap<>(locPropsBefore.size());
|
||||||
|
|
||||||
@@ -421,7 +423,7 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
{
|
{
|
||||||
return mapToNodeAspects(nodeService.getAspects(nodeRef));
|
return mapToNodeAspects(nodeService.getAspects(nodeRef));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getPrimaryHierarchy(NodeRef nodeRef, boolean showLeaf)
|
public List<String> getPrimaryHierarchy(NodeRef nodeRef, boolean showLeaf)
|
||||||
{
|
{
|
||||||
final Path path = nodeService.getPath(nodeRef);
|
final Path path = nodeService.getPath(nodeRef);
|
||||||
@@ -431,16 +433,17 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
/**
|
/**
|
||||||
* Gathers node's secondary parents.
|
* Gathers node's secondary parents.
|
||||||
*
|
*
|
||||||
* @param nodeRef - node reference
|
* @param nodeRef
|
||||||
|
* - node reference
|
||||||
* @return a list of node's secondary parents.
|
* @return a list of node's secondary parents.
|
||||||
*/
|
*/
|
||||||
public List<String> getSecondaryParents(final NodeRef nodeRef)
|
public List<String> getSecondaryParents(final NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
return nodeService.getParentAssocs(nodeRef).stream()
|
return nodeService.getParentAssocs(nodeRef).stream()
|
||||||
.filter(not(ChildAssociationRef::isPrimary))
|
.filter(not(ChildAssociationRef::isPrimary))
|
||||||
.map(ChildAssociationRef::getParentRef)
|
.map(ChildAssociationRef::getParentRef)
|
||||||
.map(NodeRef::getId)
|
.map(NodeRef::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PermissionService getPermissionService()
|
public PermissionService getPermissionService()
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.repo.event2.replacer;
|
package org.alfresco.repo.event2;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@@ -32,6 +32,7 @@ import java.util.UUID;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.event2.replacer.PropertyReplacer;
|
||||||
import org.alfresco.repo.transfer.TransferModel;
|
import org.alfresco.repo.transfer.TransferModel;
|
||||||
|
|
||||||
public class PropertyReplacerUnitTest
|
public class PropertyReplacerUnitTest
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
* Copyright (C) 2005 - 2025 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -30,12 +30,12 @@ import org.junit.runners.Suite;
|
|||||||
import org.junit.runners.Suite.SuiteClasses;
|
import org.junit.runners.Suite.SuiteClasses;
|
||||||
|
|
||||||
@RunWith(Suite.class)
|
@RunWith(Suite.class)
|
||||||
@SuiteClasses({ EventFilterUnitTest.class,
|
@SuiteClasses({EventFilterUnitTest.class,
|
||||||
EventConsolidatorUnitTest.class,
|
EventConsolidatorUnitTest.class,
|
||||||
EventJSONSchemaUnitTest.class,
|
EventJSONSchemaUnitTest.class,
|
||||||
EnqueuingEventSenderUnitTest.class,
|
EnqueuingEventSenderUnitTest.class,
|
||||||
NodeResourceHelperUnitTest.class
|
NodeResourceHelperUnitTest.class,
|
||||||
|
PropertyReplacerUnitTest.class
|
||||||
})
|
})
|
||||||
public class RepoEvent2UnitSuite
|
public class RepoEvent2UnitSuite
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user