diff --git a/repository/src/main/java/org/alfresco/repo/event2/NodeResourceHelper.java b/repository/src/main/java/org/alfresco/repo/event2/NodeResourceHelper.java index cb9f08576e..c901c548c4 100644 --- a/repository/src/main/java/org/alfresco/repo/event2/NodeResourceHelper.java +++ b/repository/src/main/java/org/alfresco/repo/event2/NodeResourceHelper.java @@ -42,6 +42,9 @@ import java.util.Set; import java.util.stream.Collectors; 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.repo.event.v1.model.ContentInfo; @@ -69,9 +72,6 @@ import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.util.PathUtil; 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. @@ -82,15 +82,15 @@ public class NodeResourceHelper implements InitializingBean { private static final Log LOGGER = LogFactory.getLog(NodeResourceHelper.class); - protected NodeService nodeService; - protected DictionaryService dictionaryService; - protected PersonService personService; + protected NodeService nodeService; + protected DictionaryService dictionaryService; + protected PersonService personService; protected EventFilterRegistry eventFilterRegistry; - protected NamespaceService namespaceService; - protected PermissionService permissionService; - protected PropertyReplacer propertyReplacer; + protected NamespaceService namespaceService; + protected PermissionService permissionService; + protected PropertyReplacer propertyReplacer; - private NodeAspectFilter nodeAspectFilter; + private NodeAspectFilter nodeAspectFilter; private NodePropertyFilter nodePropertyFilter; @Override @@ -127,7 +127,7 @@ public class NodeResourceHelper implements InitializingBean { this.permissionService = permissionService; } - + // To make IntelliJ stop complaining about unused method! @SuppressWarnings("unused") public void setEventFilterRegistry(EventFilterRegistry eventFilterRegistry) @@ -156,22 +156,22 @@ public class NodeResourceHelper implements InitializingBean Map mapUserCache = new HashMap<>(2); return NodeResource.builder() - .setId(nodeRef.getId()) - .setName((String) properties.get(ContentModel.PROP_NAME)) - .setNodeType(getQNamePrefixString(type)) - .setIsFile(isSubClass(type, ContentModel.TYPE_CONTENT)) - .setIsFolder(isSubClass(type, ContentModel.TYPE_FOLDER)) - .setCreatedByUser(getUserInfo((String) properties.get(ContentModel.PROP_CREATOR), mapUserCache)) - .setCreatedAt(getZonedDateTime((Date)properties.get(ContentModel.PROP_CREATED))) - .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)) - .setLocalizedProperties(mapToNodeLocalizedProperties(properties)) - .setAspectNames(getMappedAspects(nodeRef)) - .setSecondaryParents(getSecondaryParents(nodeRef)); + .setId(nodeRef.getId()) + .setName((String) properties.get(ContentModel.PROP_NAME)) + .setNodeType(getQNamePrefixString(type)) + .setIsFile(isSubClass(type, ContentModel.TYPE_CONTENT)) + .setIsFolder(isSubClass(type, ContentModel.TYPE_FOLDER)) + .setCreatedByUser(getUserInfo((String) properties.get(ContentModel.PROP_CREATOR), mapUserCache)) + .setCreatedAt(getZonedDateTime((Date) properties.get(ContentModel.PROP_CREATED))) + .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)) + .setLocalizedProperties(mapToNodeLocalizedProperties(properties)) + .setAspectNames(getMappedAspects(nodeRef)) + .setSecondaryParents(getSecondaryParents(nodeRef)); } private boolean isSubClass(QName className, QName ofClassQName) @@ -179,17 +179,18 @@ public class NodeResourceHelper implements InitializingBean return dictionaryService.isSubClass(className, ofClassQName); } - private String getPrimaryAssocQName(NodeRef nodeRef) + private String getPrimaryAssocQName(NodeRef nodeRef) { String result = null; - try + try { ChildAssociationRef primaryParent = nodeService.getPrimaryParent(nodeRef); - if(primaryParent != null && primaryParent.getQName() != null) + if (primaryParent != null && primaryParent.getQName() != null) { result = primaryParent.getQName().getPrefixedQName(namespaceService).getPrefixString(); } - } catch (NamespaceException namespaceException) + } + catch (NamespaceException namespaceException) { 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 HashMap localizedValues = new HashMap<>(mlTextValue.size()); mlTextValue.forEach((locale, text) -> { - Serializable replacedValue = propertyReplacer.replace(k, v); + Serializable replacedValue = propertyReplacer.replace(k, text); localizedValues.put(locale.toString(), replacedValue.toString()); }); filteredProps.put(getQNamePrefixString(k), localizedValues); @@ -270,7 +271,7 @@ public class NodeResourceHelper implements InitializingBean { String sysUserName = AuthenticationUtil.getSystemUserName(); if (userName.equals(sysUserName) || (AuthenticationUtil.isMtEnabled() - && userName.startsWith(sysUserName + "@"))) + && userName.startsWith(sysUserName + "@"))) { 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 it in the form {uri}local. + * 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. * - * @param k QName - * @return a String representing the QName in the format prefix:local or {uri}local. + * @param k + * QName + * @return a String representing the QName in the format prefix:local or {uri}local. */ public String getQNamePrefixString(QName k) { @@ -353,7 +354,7 @@ public class NodeResourceHelper implements InitializingBean public QName getNodeType(NodeRef nodeRef) { - return nodeService.getType(nodeRef); + return nodeService.getType(nodeRef); } public Serializable getProperty(NodeRef nodeRef, QName qName) @@ -363,13 +364,14 @@ public class NodeResourceHelper implements InitializingBean public Map 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(); MLPropertyInterceptor.setMLAware(true); try { return nodeService.getProperties(nodeRef); - } finally + } + finally { MLPropertyInterceptor.setMLAware(toRestore); } @@ -388,7 +390,7 @@ public class NodeResourceHelper implements InitializingBean } static Map> getLocalizedPropertiesBefore(Map> locPropsBefore, - Map> locPropsAfter) + Map> locPropsAfter) { final Map> result = new HashMap<>(locPropsBefore.size()); @@ -421,7 +423,7 @@ public class NodeResourceHelper implements InitializingBean { return mapToNodeAspects(nodeService.getAspects(nodeRef)); } - + public List getPrimaryHierarchy(NodeRef nodeRef, boolean showLeaf) { final Path path = nodeService.getPath(nodeRef); @@ -431,16 +433,17 @@ public class NodeResourceHelper implements InitializingBean /** * Gathers node's secondary parents. * - * @param nodeRef - node reference + * @param nodeRef + * - node reference * @return a list of node's secondary parents. */ public List getSecondaryParents(final NodeRef nodeRef) { return nodeService.getParentAssocs(nodeRef).stream() - .filter(not(ChildAssociationRef::isPrimary)) - .map(ChildAssociationRef::getParentRef) - .map(NodeRef::getId) - .collect(Collectors.toList()); + .filter(not(ChildAssociationRef::isPrimary)) + .map(ChildAssociationRef::getParentRef) + .map(NodeRef::getId) + .collect(Collectors.toList()); } public PermissionService getPermissionService() diff --git a/repository/src/test/java/org/alfresco/repo/event2/replacer/PropertyReplacerUnitTest.java b/repository/src/test/java/org/alfresco/repo/event2/PropertyReplacerUnitTest.java similarity index 95% rename from repository/src/test/java/org/alfresco/repo/event2/replacer/PropertyReplacerUnitTest.java rename to repository/src/test/java/org/alfresco/repo/event2/PropertyReplacerUnitTest.java index e004c382dd..e862273061 100644 --- a/repository/src/test/java/org/alfresco/repo/event2/replacer/PropertyReplacerUnitTest.java +++ b/repository/src/test/java/org/alfresco/repo/event2/PropertyReplacerUnitTest.java @@ -23,7 +23,7 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.repo.event2.replacer; +package org.alfresco.repo.event2; import static org.junit.Assert.assertEquals; @@ -32,6 +32,7 @@ import java.util.UUID; import org.junit.Test; import org.alfresco.model.ContentModel; +import org.alfresco.repo.event2.replacer.PropertyReplacer; import org.alfresco.repo.transfer.TransferModel; public class PropertyReplacerUnitTest diff --git a/repository/src/test/java/org/alfresco/repo/event2/RepoEvent2UnitSuite.java b/repository/src/test/java/org/alfresco/repo/event2/RepoEvent2UnitSuite.java index b012df9ff4..aad9e99a10 100644 --- a/repository/src/test/java/org/alfresco/repo/event2/RepoEvent2UnitSuite.java +++ b/repository/src/test/java/org/alfresco/repo/event2/RepoEvent2UnitSuite.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2023 Alfresco Software Limited + * Copyright (C) 2005 - 2025 Alfresco Software Limited * %% * This file is part of the Alfresco software. * 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; @RunWith(Suite.class) -@SuiteClasses({ EventFilterUnitTest.class, - EventConsolidatorUnitTest.class, - EventJSONSchemaUnitTest.class, - EnqueuingEventSenderUnitTest.class, - NodeResourceHelperUnitTest.class +@SuiteClasses({EventFilterUnitTest.class, + EventConsolidatorUnitTest.class, + EventJSONSchemaUnitTest.class, + EnqueuingEventSenderUnitTest.class, + NodeResourceHelperUnitTest.class, + PropertyReplacerUnitTest.class }) public class RepoEvent2UnitSuite -{ -} +{}