Fix for SEARCH-228 SOLR - version store nodes are indexed with the wrong ACL and PATH

- Index the ACL and PATHs for the current live version (which will not be updated).

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@132065 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2016-11-01 22:00:11 +00:00
parent 1e97c7c275
commit 6e3ab8a166

View File

@@ -1,28 +1,28 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 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
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* 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.solr; package org.alfresco.repo.solr;
import java.io.Serializable; import java.io.Serializable;
@@ -52,10 +52,13 @@ import org.alfresco.repo.domain.solr.SOLRDAO;
import org.alfresco.repo.index.shard.ShardRegistry; import org.alfresco.repo.index.shard.ShardRegistry;
import org.alfresco.repo.index.shard.ShardState; import org.alfresco.repo.index.shard.ShardState;
import org.alfresco.repo.search.AspectIndexFilter; import org.alfresco.repo.search.AspectIndexFilter;
import org.alfresco.repo.search.TypeIndexFilter; import org.alfresco.repo.search.TypeIndexFilter;
import org.alfresco.repo.search.impl.QueryParserUtils; import org.alfresco.repo.search.impl.QueryParserUtils;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantService; import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.version.Version2Model;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.repo.version.common.VersionUtil;
import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
@@ -70,13 +73,11 @@ import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.repository.Path.ChildAssocElement; import org.alfresco.service.cmr.repository.Path.ChildAssocElement;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.security.OwnableService; import org.alfresco.service.cmr.security.OwnableService;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import org.alfresco.util.PropertyCheck; import org.alfresco.util.PropertyCheck;
import com.sun.xml.txw2.NamespaceResolver;
/** /**
* Component providing data for SOLR tracking * Component providing data for SOLR tracking
@@ -98,7 +99,7 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
private boolean cacheAncestors =true; private boolean cacheAncestors =true;
private TypeIndexFilter typeIndexFilter; private TypeIndexFilter typeIndexFilter;
private AspectIndexFilter aspectIndexFilter; private AspectIndexFilter aspectIndexFilter;
private ShardRegistry shardRegistry; private ShardRegistry shardRegistry;
private NamespaceService namespaceService; private NamespaceService namespaceService;
@@ -182,11 +183,11 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
this.shardRegistry = shardRegistry; this.shardRegistry = shardRegistry;
} }
public void setNamespaceService(NamespaceService namespaceService) public void setNamespaceService(NamespaceService namespaceService)
{ {
this.namespaceService = namespaceService; this.namespaceService = namespaceService;
} }
/** /**
* Initialize * Initialize
*/ */
@@ -202,7 +203,7 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
PropertyCheck.mandatory(this, "dictionaryDAO", dictionaryDAO); PropertyCheck.mandatory(this, "dictionaryDAO", dictionaryDAO);
PropertyCheck.mandatory(this, "aclDAO", aclDAO); PropertyCheck.mandatory(this, "aclDAO", aclDAO);
PropertyCheck.mandatory(this, "typeIndexFilter", typeIndexFilter); PropertyCheck.mandatory(this, "typeIndexFilter", typeIndexFilter);
PropertyCheck.mandatory(this, "aspectIndexFilter", aspectIndexFilter); PropertyCheck.mandatory(this, "aspectIndexFilter", aspectIndexFilter);
PropertyCheck.mandatory(this, "namespaceService", namespaceService); PropertyCheck.mandatory(this, "namespaceService", namespaceService);
} }
@@ -354,21 +355,21 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
public void getNodes(NodeParameters nodeParameters, NodeQueryCallback callback) public void getNodes(NodeParameters nodeParameters, NodeQueryCallback callback)
{ {
if(enabled) if(enabled)
{ {
QName shardPropertQName = null; QName shardPropertQName = null;
if(nodeParameters.getShardProperty() != null) if(nodeParameters.getShardProperty() != null)
{ {
PropertyDefinition pdef = QueryParserUtils.matchPropertyDefinition(NamespaceService.CONTENT_MODEL_1_0_URI, namespaceService, dictionaryService, nodeParameters.getShardProperty()); PropertyDefinition pdef = QueryParserUtils.matchPropertyDefinition(NamespaceService.CONTENT_MODEL_1_0_URI, namespaceService, dictionaryService, nodeParameters.getShardProperty());
if(pdef == null) if(pdef == null)
{ {
throw new AlfrescoRuntimeException("Invalid shard property: "+nodeParameters.getShardProperty()); throw new AlfrescoRuntimeException("Invalid shard property: "+nodeParameters.getShardProperty());
} }
if((!pdef.getDataType().getName().equals(DataTypeDefinition.TEXT)) && (!pdef.getDataType().getName().equals(DataTypeDefinition.DATE)) && (!pdef.getDataType().getName().equals(DataTypeDefinition.DATETIME))) if((!pdef.getDataType().getName().equals(DataTypeDefinition.TEXT)) && (!pdef.getDataType().getName().equals(DataTypeDefinition.DATE)) && (!pdef.getDataType().getName().equals(DataTypeDefinition.DATETIME)))
{ {
throw new AlfrescoRuntimeException("Unsupported shard property type: "+(pdef.getDataType().getName() + " for " +nodeParameters.getShardProperty())); throw new AlfrescoRuntimeException("Unsupported shard property type: "+(pdef.getDataType().getName() + " for " +nodeParameters.getShardProperty()));
} }
shardPropertQName = pdef.getName(); shardPropertQName = pdef.getName();
} }
List<Node> nodes = solrDAO.getNodes(nodeParameters, shardPropertQName); List<Node> nodes = solrDAO.getNodes(nodeParameters, shardPropertQName);
@@ -685,9 +686,9 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
public long getCRC(Long nodeId) public long getCRC(Long nodeId)
{ {
Status status = nodeDAO.getNodeIdStatus(nodeId); //Status status = nodeDAO.getNodeIdStatus(nodeId);
Set<QName> aspects = getNodeAspects(nodeId); //Set<QName> aspects = getNodeAspects(nodeId);
Map<QName, Serializable> props = getProperties(nodeId); //Map<QName, Serializable> props = getProperties(nodeId);
//Category membership does not cascade to children - only the node needs reindexing, not its children //Category membership does not cascade to children - only the node needs reindexing, not its children
//This was producing cascade updates that were not required //This was producing cascade updates that were not required
@@ -781,6 +782,12 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
continue; continue;
} }
NodeRef nodeRef = status.getNodeRef(); NodeRef nodeRef = status.getNodeRef();
NodeRef unversionedNodeRef = null;
if(isVersionNodeRef(nodeRef))
{
unversionedNodeRef = convertVersionNodeRefToVersionedNodeRef(VersionUtil.convertNodeRef(nodeRef));
}
NodeMetaData nodeMetaData = new NodeMetaData(); NodeMetaData nodeMetaData = new NodeMetaData();
nodeMetaData.setNodeId(nodeId); nodeMetaData.setNodeId(nodeId);
@@ -803,8 +810,22 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
Map<QName, Serializable> props = null; Map<QName, Serializable> props = null;
Set<QName> aspects = null; Set<QName> aspects = null;
nodeMetaData.setAclId(nodeDAO.getNodeAclId(nodeId)); Status unversionedStatus = null;
if(unversionedNodeRef != null)
{
unversionedStatus = nodeDAO.getNodeRefStatus(unversionedNodeRef);
}
if(unversionedStatus != null)
{
nodeMetaData.setAclId(nodeDAO.getNodeAclId(unversionedStatus.getDbId()));
}
else
{
nodeMetaData.setAclId(nodeDAO.getNodeAclId(nodeId));
}
if(includeType) if(includeType)
{ {
@@ -903,8 +924,8 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
} }
List<Path> directPaths = nodeDAO.getPaths(new Pair<Long, NodeRef>(nodeId, status.getNodeRef()), false); List<Path> directPaths = nodeDAO.getPaths(new Pair<Long, NodeRef>(nodeId, status.getNodeRef()), false);
Collection<Pair<Path, QName>> paths = new ArrayList<Pair<Path, QName>>(directPaths.size() + categoryPaths.getPaths().size()); Collection<Pair<Path, QName>> paths = new ArrayList<Pair<Path, QName>>(directPaths.size() + categoryPaths.getPaths().size());
for (Path path : directPaths) for (Path path : directPaths)
{ {
paths.add(new Pair<Path, QName>(path.getBaseNamePath(tenantService), null)); paths.add(new Pair<Path, QName>(path.getBaseNamePath(tenantService), null));
@@ -913,6 +934,14 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
{ {
paths.add(new Pair<Path, QName>(catPair.getFirst().getBaseNamePath(tenantService), catPair.getSecond())); paths.add(new Pair<Path, QName>(catPair.getFirst().getBaseNamePath(tenantService), catPair.getSecond()));
} }
if(unversionedStatus != null)
{
List<Path> unversionedPaths = nodeDAO.getPaths(new Pair<Long, NodeRef>(unversionedStatus.getDbId(), unversionedStatus.getNodeRef()), false);
for (Path path : unversionedPaths)
{
paths.add(new Pair<Path, QName>(path.getBaseNamePath(tenantService), null));
}
}
nodeMetaData.setPaths(paths); nodeMetaData.setPaths(paths);
@@ -1123,6 +1152,41 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
} }
} }
private boolean isVersionNodeRef(NodeRef nodeRef)
{
return nodeRef.getStoreRef().getProtocol().equals(VersionModel.STORE_PROTOCOL) || nodeRef.getStoreRef().getIdentifier().equals(Version2Model.STORE_ID);
}
@SuppressWarnings("deprecation")
protected NodeRef convertVersionNodeRefToVersionedNodeRef(NodeRef versionNodeRef)
{
Status status = nodeDAO.getNodeRefStatus(versionNodeRef);
if (status == null)
{
return versionNodeRef;
}
Map<QName, Serializable> properties = nodeDAO.getNodeProperties(status.getDbId());
NodeRef nodeRef = null;
// Switch VersionStore depending on configured impl
if (versionNodeRef.getStoreRef().getIdentifier().equals(Version2Model.STORE_ID))
{
// V2 version store (eg. workspace://version2Store)
nodeRef = (NodeRef)properties.get(Version2Model.PROP_QNAME_FROZEN_NODE_REF);
}
else if (versionNodeRef.getStoreRef().getIdentifier().equals(VersionModel.STORE_ID))
{
// Deprecated V1 version store (eg. workspace://lightWeightVersionStore)
nodeRef = new NodeRef((String) properties.get(VersionModel.PROP_QNAME_FROZEN_NODE_STORE_PROTOCOL),
(String) properties.get(VersionModel.PROP_QNAME_FROZEN_NODE_STORE_ID),
(String) properties.get(VersionModel.PROP_QNAME_FROZEN_NODE_ID));
}
return nodeRef;
}
private QName getNodeType(Long nodeId) private QName getNodeType(Long nodeId)
{ {
QName result = nodeDAO.getNodeType(nodeId); QName result = nodeDAO.getNodeType(nodeId);