mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged HEAD (5.1) to 5.1.N (5.1.1)
119450 mcozma: Merged BRANCHES/DEV/VF_REP_INT_51 to HEAD ACE-4716 Can't rename a document in a virtual context from CMIS ACE-4752 Type virtualization method does not work ACE-4717 Document name is renamed when making "Check in" for a document edited in Google Docs ACE-4700 Can't upload to a virtual folder when filename starts with a number and includes dashes git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@119613 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -435,6 +435,8 @@ public class FileFolderServiceImpl extends AbstractBaseCopyService implements Fi
|
||||
* @see org.alfresco.service.cmr.model.FileFolderService#list(org.alfresco.service.cmr.repository.NodeRef, boolean, boolean, java.util.Set, org.alfresco.service.cmr.model.PagingSortRequest)
|
||||
*/
|
||||
@Auditable(parameters = {"contextNodeRef", "files", "folders", "ignoreQNames", "sortProps", "pagingRequest"})
|
||||
@Override
|
||||
@Extend(traitAPI = FileFolderServiceTrait.class, extensionAPI = FileFolderServiceExtension.class)
|
||||
public PagingResults<FileInfo> list(NodeRef contextNodeRef,
|
||||
boolean files,
|
||||
boolean folders,
|
||||
@@ -1251,7 +1253,7 @@ public class FileFolderServiceImpl extends AbstractBaseCopyService implements Fi
|
||||
{
|
||||
return createImpl(parentNodeRef, name, typeQName, assocQName);
|
||||
}
|
||||
|
||||
|
||||
private FileInfo createImpl(NodeRef parentNodeRef, String name, QName typeQName, QName assocQName) throws FileExistsException
|
||||
{
|
||||
// set up initial properties
|
||||
@@ -1785,5 +1787,21 @@ public class FileFolderServiceImpl extends AbstractBaseCopyService implements Fi
|
||||
return thisService.rename(sourceNodeRef, newName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public PagingResults<FileInfo> list(NodeRef contextNodeRef,
|
||||
boolean files,
|
||||
boolean folders,
|
||||
Set<QName> ignoreQNames,
|
||||
List<Pair<QName, Boolean>> sortProps,
|
||||
PagingRequest pagingRequest)
|
||||
{
|
||||
return thisService.list(contextNodeRef,
|
||||
files,
|
||||
folders,
|
||||
ignoreQNames,
|
||||
sortProps,
|
||||
pagingRequest);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.model.filefolder.traitextender;
|
||||
|
||||
import java.util.List;
|
||||
@@ -37,6 +38,9 @@ public interface FileFolderServiceExtension
|
||||
PagingResults<FileInfo> list(NodeRef contextNodeRef, boolean files, boolean folders, String pattern,
|
||||
Set<QName> ignoreQNames, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest);
|
||||
|
||||
PagingResults<FileInfo> list(NodeRef contextNodeRef, boolean files, boolean folders, Set<QName> ignoreQNames,
|
||||
List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest);
|
||||
|
||||
PagingResults<FileInfo> list(NodeRef rootNodeRef, Set<QName> searchTypeQNames, Set<QName> ignoreAspectQNames,
|
||||
List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest);
|
||||
|
||||
|
@@ -47,6 +47,9 @@ public interface FileFolderServiceTrait extends Trait
|
||||
PagingResults<FileInfo> list(final NodeRef contextNodeRef, boolean files, boolean folders, String pattern,
|
||||
Set<QName> ignoreQNames, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest);
|
||||
|
||||
PagingResults<FileInfo> list(NodeRef contextNodeRef, boolean files, boolean folders, Set<QName> ignoreQNames,
|
||||
List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest);
|
||||
|
||||
PagingResults<FileInfo> list(NodeRef rootNodeRef, Set<QName> searchTypeQNames, Set<QName> ignoreAspectQNames,
|
||||
List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest);
|
||||
|
||||
@@ -55,6 +58,6 @@ public interface FileFolderServiceTrait extends Trait
|
||||
|
||||
Pair<Set<QName>, Set<QName>> buildSearchTypesAndIgnoreAspects(boolean files, boolean folders,
|
||||
Set<QName> ignoreQNameTypes);
|
||||
|
||||
|
||||
FileInfo rename(NodeRef sourceNodeRef, String newName) throws FileExistsException, FileNotFoundException;
|
||||
}
|
||||
|
@@ -91,7 +91,7 @@ public interface ActualEnvironment
|
||||
Object createScriptVirtualContext(VirtualContext context) throws ActualEnvironmentException;
|
||||
|
||||
NodeRef findNodeRef(String referenceType, String[] reference);
|
||||
|
||||
|
||||
NodeRef findQNamePath(String[] patheElements);
|
||||
|
||||
boolean exists(NodeRef nodeRef);
|
||||
@@ -102,10 +102,9 @@ public interface ActualEnvironment
|
||||
|
||||
FileInfo create(NodeRef parentNodeRef, String name, QName typeQName) throws FileExistsException;
|
||||
|
||||
ContentWriter getWriter(NodeRef nodeRef, QName propertyQName, boolean update) throws InvalidNodeRefException,
|
||||
InvalidTypeException;
|
||||
ContentWriter getWriter(NodeRef nodeRef, QName propertyQName, boolean update)
|
||||
throws InvalidNodeRefException, InvalidTypeException;
|
||||
|
||||
void addAspect(NodeRef nodeRef, QName aspectTypeQName, Map<QName, Serializable> aspectProperties)
|
||||
throws InvalidNodeRefException, InvalidAspectException;
|
||||
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.jscript.ClasspathScriptLocation;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.virtual.config.NodeRefResolver;
|
||||
import org.alfresco.repo.virtual.ref.Reference;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.dictionary.InvalidAspectException;
|
||||
import org.alfresco.service.cmr.dictionary.InvalidTypeException;
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
package org.alfresco.repo.virtual;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -26,6 +27,10 @@ import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
|
||||
import org.alfresco.repo.jscript.ScriptNode;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.Path;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ISO9075;
|
||||
|
||||
/**
|
||||
* JavaScript API {@link VirtualContext} adapter.
|
||||
@@ -40,6 +45,8 @@ public class AlfrescoScriptVirtualContext extends BaseScopableProcessorExtension
|
||||
|
||||
public static final String ACTUAL_PATH_PH = "ACTUAL_PATH";
|
||||
|
||||
public static final String ACTUAL_ISO9075_PATH_PH = "ACTUAL_ISO9075_PATH";
|
||||
|
||||
private VirtualContext context;
|
||||
|
||||
private ServiceRegistry serviceRegistry;
|
||||
@@ -54,18 +61,70 @@ public class AlfrescoScriptVirtualContext extends BaseScopableProcessorExtension
|
||||
this.placeholders = createPlaceHolders();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an array containing the plain qname path at index 0 and the
|
||||
* ISO9075 element-encoded qname path at index 1
|
||||
*/
|
||||
private String[] createQNamePaths()
|
||||
{
|
||||
final NamespaceService ns = serviceRegistry.getNamespaceService();
|
||||
final Map<String, String> cache = new HashMap<String, String>();
|
||||
final StringBuilder bufPlain = new StringBuilder(128);
|
||||
final StringBuilder bufISO9075 = new StringBuilder(128);
|
||||
|
||||
final Path path = serviceRegistry.getNodeService().getPath(context.getActualNodeRef());
|
||||
for (final Path.Element e : path)
|
||||
{
|
||||
if (e instanceof Path.ChildAssocElement)
|
||||
{
|
||||
final QName qname = ((Path.ChildAssocElement) e).getRef().getQName();
|
||||
if (qname != null)
|
||||
{
|
||||
String prefix = cache.get(qname.getNamespaceURI());
|
||||
if (prefix == null)
|
||||
{
|
||||
// first request for this namespace prefix, get and
|
||||
// cache result
|
||||
Collection<String> prefixes = ns.getPrefixes(qname.getNamespaceURI());
|
||||
prefix = prefixes.size() != 0 ? prefixes.iterator().next() : "";
|
||||
cache.put(qname.getNamespaceURI(),
|
||||
prefix);
|
||||
}
|
||||
bufISO9075.append('/').append(prefix).append(':').append(ISO9075.encode(qname.getLocalName()));
|
||||
bufPlain.append('/').append(prefix).append(':').append(qname.getLocalName());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bufISO9075.append('/').append(e.toString());
|
||||
bufPlain.append('/').append(e.toString());
|
||||
}
|
||||
}
|
||||
String[] qnamePaths = new String[] { bufPlain.toString(), bufISO9075.toString() };
|
||||
|
||||
return qnamePaths;
|
||||
}
|
||||
|
||||
// TODO: extract placeholder interface. make placeholders configurable.
|
||||
// TODO: extract open-close-configurable placeholders
|
||||
private Map<String, String> createPlaceHolders()
|
||||
{
|
||||
Map<String, String> newPlaceholders = new HashMap<>();
|
||||
String user = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
|
||||
// TODO: extract open-close-configurable placeholders
|
||||
newPlaceholders.put(CURRENT_USER_PH,
|
||||
user);
|
||||
// TODO: can we replace getQnamePath usage
|
||||
|
||||
String[] paths = createQNamePaths();
|
||||
|
||||
// the actual path will contain the ISO9075 encoded qname path
|
||||
// this was reverted from a dual placeholder implementation (see CM-523)
|
||||
newPlaceholders.put(ACTUAL_PATH_PH,
|
||||
getActualNode().getQnamePath());
|
||||
paths[1]);
|
||||
|
||||
// newPlaceholders.put(ACTUAL_ISO9075_PATH_PH,
|
||||
// paths[1]);
|
||||
|
||||
return newPlaceholders;
|
||||
}
|
||||
|
||||
|
@@ -48,10 +48,10 @@ import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.model.FileNotFoundException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.traitextender.SpringBeanExtension;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
public class VirtualFileFolderServiceExtension extends SpringBeanExtension<FileFolderServiceExtension, FileFolderServiceTrait>
|
||||
public class VirtualFileFolderServiceExtension
|
||||
extends VirtualSpringBeanExtension<FileFolderServiceExtension, FileFolderServiceTrait>
|
||||
implements FileFolderServiceExtension
|
||||
{
|
||||
private VirtualStore virtualStore;
|
||||
@@ -154,17 +154,16 @@ public class VirtualFileFolderServiceExtension extends SpringBeanExtension<FileF
|
||||
Set<QName>[] searchAndIgnore = (Set<QName>[]) Array.newInstance(Set.class,
|
||||
3);
|
||||
|
||||
Pair<Set<QName>, Set<QName>> searchTypesAndIgnoreAspects = getTrait()
|
||||
.buildSearchTypesAndIgnoreAspects(files,
|
||||
folders,
|
||||
ignoreQNames);
|
||||
Pair<Set<QName>, Set<QName>> searchTypesAndIgnoreAspects = getTrait().buildSearchTypesAndIgnoreAspects(files,
|
||||
folders,
|
||||
ignoreQNames);
|
||||
if (searchTypesAndIgnoreAspects != null)
|
||||
{
|
||||
Set<QName> searchTypesQNames = searchTypesAndIgnoreAspects.getFirst();
|
||||
Set<QName> ignoreAspectsQNames = searchTypesAndIgnoreAspects.getSecond();
|
||||
|
||||
Set<QName> ignoreTypesQNames = null;
|
||||
if ((searchTypesQNames != null || ignoreAspectsQNames != null) && ignoreQNames!=null)
|
||||
if ((searchTypesQNames != null || ignoreAspectsQNames != null) && ignoreQNames != null)
|
||||
{
|
||||
ignoreTypesQNames = new HashSet<>(ignoreQNames);
|
||||
if (searchTypesQNames != null)
|
||||
@@ -235,8 +234,8 @@ public class VirtualFileFolderServiceExtension extends SpringBeanExtension<FileF
|
||||
}
|
||||
};
|
||||
|
||||
FileInfoPropsComparator comparator = (sortProps != null && !sortProps.isEmpty()) ? new FileInfoPropsComparator(sortProps)
|
||||
: null;
|
||||
FileInfoPropsComparator comparator = (sortProps != null && !sortProps.isEmpty())
|
||||
? new FileInfoPropsComparator(sortProps) : null;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -287,8 +286,8 @@ public class VirtualFileFolderServiceExtension extends SpringBeanExtension<FileF
|
||||
}
|
||||
|
||||
public PagingResults<FileInfo> asFileInfoResults(ActualEnvironment environment,
|
||||
final PagingResults<Reference> results, VirtualStore store) throws ReferenceEncodingException,
|
||||
VirtualizationException
|
||||
final PagingResults<Reference> results, VirtualStore store)
|
||||
throws ReferenceEncodingException, VirtualizationException
|
||||
{
|
||||
|
||||
List<Reference> virtualPage = results.getPage();
|
||||
@@ -487,10 +486,23 @@ public class VirtualFileFolderServiceExtension extends SpringBeanExtension<FileF
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo rename(NodeRef sourceNodeRef, String newName) throws FileExistsException, FileNotFoundException
|
||||
public FileInfo rename(NodeRef sourceNodeRef, String newName) throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
return getTrait().rename(virtualStore.materializeIfPossible(sourceNodeRef),
|
||||
newName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagingResults<FileInfo> list(NodeRef contextNodeRef, boolean files, boolean folders, Set<QName> ignoreQNames,
|
||||
List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest)
|
||||
{
|
||||
|
||||
return VirtualFileFolderServiceExtension.this.list(contextNodeRef,
|
||||
files,
|
||||
folders,
|
||||
null,
|
||||
ignoreQNames,
|
||||
sortProps,
|
||||
pagingRequest);
|
||||
}
|
||||
}
|
||||
|
@@ -66,12 +66,11 @@ import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.QNamePattern;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.alfresco.traitextender.SpringBeanExtension;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class VirtualNodeServiceExtension extends SpringBeanExtension<NodeServiceExtension, NodeServiceTrait>
|
||||
public class VirtualNodeServiceExtension extends VirtualSpringBeanExtension<NodeServiceExtension, NodeServiceTrait>
|
||||
implements NodeServiceExtension
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(VirtualNodeServiceExtension.class);
|
||||
@@ -102,13 +101,14 @@ public class VirtualNodeServiceExtension extends SpringBeanExtension<NodeService
|
||||
{
|
||||
if (Reference.isReference(nodeRef))
|
||||
{
|
||||
boolean isNodeProtocol = Reference.fromNodeRef(nodeRef).getProtocol().equals(Protocols.NODE.protocol);
|
||||
if (VirtualContentModel.ASPECT_VIRTUAL.equals(aspectQName))
|
||||
{
|
||||
return true;
|
||||
return !isNodeProtocol;
|
||||
}
|
||||
else if (VirtualContentModel.ASPECT_VIRTUAL_DOCUMENT.equals(aspectQName) && Reference.fromNodeRef(nodeRef).getProtocol().equals(Protocols.NODE.protocol))
|
||||
else if (VirtualContentModel.ASPECT_VIRTUAL_DOCUMENT.equals(aspectQName))
|
||||
{
|
||||
return true;
|
||||
return isNodeProtocol;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -258,22 +258,13 @@ public class VirtualNodeServiceExtension extends SpringBeanExtension<NodeService
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isVirtualContextFolder(NodeRef nodeRef)
|
||||
{
|
||||
|
||||
boolean isReference=Reference.isReference(nodeRef);
|
||||
boolean isFolder=environment.isSubClass(environment.getType(nodeRef),
|
||||
ContentModel.TYPE_FOLDER);
|
||||
boolean virtualContext=hasAspect(nodeRef,VirtualContentModel.ASPECT_VIRTUAL_DOCUMENT);
|
||||
return isReference && isFolder && virtualContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChildAssociationRef createNode(NodeRef parentRef, QName assocTypeQName, QName assocQName,
|
||||
QName nodeTypeQName, Map<QName, Serializable> properties)
|
||||
{
|
||||
NodeServiceTrait theTrait = getTrait();
|
||||
if (Reference.isReference(parentRef) && !isVirtualContextFolder(parentRef))
|
||||
if (Reference.isReference(parentRef) && !isVirtualContextFolder(parentRef,
|
||||
environment))
|
||||
{
|
||||
// CM-533 Suppress options to create folders in a virtual folder
|
||||
// (repo)
|
||||
@@ -357,8 +348,10 @@ public class VirtualNodeServiceExtension extends SpringBeanExtension<NodeService
|
||||
else
|
||||
{
|
||||
QName materialAssocQName = materializeAssocQName(assocQName);
|
||||
if(isVirtualContextFolder(parentRef)){
|
||||
parentRef=virtualStore.materializeIfPossible(parentRef);
|
||||
if (isVirtualContextFolder(parentRef,
|
||||
environment))
|
||||
{
|
||||
parentRef = virtualStore.materializeIfPossible(parentRef);
|
||||
}
|
||||
return theTrait.createNode(parentRef,
|
||||
assocTypeQName,
|
||||
|
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
package org.alfresco.repo.virtual.bundle;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.virtual.ActualEnvironment;
|
||||
import org.alfresco.repo.virtual.VirtualContentModel;
|
||||
import org.alfresco.repo.virtual.ref.Reference;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.traitextender.SpringBeanExtension;
|
||||
import org.alfresco.traitextender.Trait;
|
||||
|
||||
public abstract class VirtualSpringBeanExtension<E, T extends Trait> extends SpringBeanExtension<E, T>
|
||||
{
|
||||
public VirtualSpringBeanExtension(Class<T> traitClass)
|
||||
{
|
||||
super(traitClass);
|
||||
}
|
||||
|
||||
public boolean isVirtualContextFolder(NodeRef nodeRef, ActualEnvironment environment)
|
||||
{
|
||||
boolean isReference=Reference.isReference(nodeRef);
|
||||
boolean isFolder=environment.isSubClass(environment.getType(nodeRef),
|
||||
ContentModel.TYPE_FOLDER);
|
||||
boolean virtualContext=environment.hasAspect(nodeRef,VirtualContentModel.ASPECT_VIRTUAL_DOCUMENT);
|
||||
return isReference && isFolder && virtualContext;
|
||||
}
|
||||
}
|
@@ -19,7 +19,10 @@
|
||||
|
||||
package org.alfresco.repo.virtual.store;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
@@ -30,10 +33,12 @@ import org.alfresco.repo.virtual.config.NodeRefExpression;
|
||||
import org.alfresco.repo.virtual.ref.Protocols;
|
||||
import org.alfresco.repo.virtual.ref.Reference;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceException;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.QNamePattern;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@@ -64,7 +69,20 @@ public class TypeVirtualizationMethod extends TemplateVirtualizationMethod
|
||||
|
||||
private NodeRefExpression templatesPath;
|
||||
|
||||
private QNamePattern qnamePattern = RegexQNamePattern.MATCH_ALL;
|
||||
private QNamePattern[] qnamePatternFilters = new QNamePattern[] { RegexQNamePattern.MATCH_ALL };
|
||||
|
||||
private static final QNamePattern MATCH_NONE = new QNamePattern()
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean isMatch(QName qname)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private String filters;
|
||||
|
||||
/**
|
||||
* Thread local solving template in process indicator.<br>
|
||||
@@ -81,12 +99,120 @@ public class TypeVirtualizationMethod extends TemplateVirtualizationMethod
|
||||
|
||||
public void init()
|
||||
{
|
||||
//void
|
||||
resetFilters();
|
||||
}
|
||||
|
||||
public void setQnameFilterRegexp(String regexp)
|
||||
|
||||
private synchronized void resetFilters()
|
||||
{
|
||||
this.qnamePattern = new RegexQNamePattern(regexp);
|
||||
if (namespacePrefixResolver != null && filters != null)
|
||||
{
|
||||
this.qnamePatternFilters = asRegExpQNamePatternFilters(filters);
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
String regExpFilters = "";
|
||||
for (int i = 0; i < qnamePatternFilters.length; i++)
|
||||
{
|
||||
regExpFilters += qnamePatternFilters[i].toString() + " | ";
|
||||
}
|
||||
logger.debug("Reset type regexp filters to : " + regExpFilters);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug("Could not reset qName filters with NameSpacePrefixResolver=" + namespacePrefixResolver
|
||||
+ " and filters=" + filters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private QNamePattern[] asRegExpQNamePatternFilters(String filtersString)
|
||||
{
|
||||
String[] filters = filtersString.split(",");
|
||||
List<QNamePattern> patterns = new ArrayList<>(3);
|
||||
for (int i = 0; i < filters.length; i++)
|
||||
{
|
||||
String trimmedFilters = filters[i].trim();
|
||||
if (!trimmedFilters.isEmpty())
|
||||
{
|
||||
if ("*".equals(trimmedFilters))
|
||||
{
|
||||
patterns.clear();
|
||||
patterns.add(RegexQNamePattern.MATCH_ALL);
|
||||
break;
|
||||
}
|
||||
|
||||
if ("none".equals(trimmedFilters))
|
||||
{
|
||||
patterns.clear();
|
||||
patterns.add(MATCH_NONE);
|
||||
break;
|
||||
}
|
||||
|
||||
String[] components = filters[i].split(":");
|
||||
if (components == null || components.length != 2 || components[0].trim().isEmpty()
|
||||
|| components[1].trim().isEmpty())
|
||||
{
|
||||
throw new IllegalArgumentException("Illegal filters string " + filtersString
|
||||
+ ". Expected <prefix>:<name> | <prefix>:'*' instead of " + filters[i]);
|
||||
}
|
||||
try
|
||||
{
|
||||
String uri = namespacePrefixResolver.getNamespaceURI(components[0]);
|
||||
|
||||
if (uri == null)
|
||||
{
|
||||
// replicate expected resolver behavior
|
||||
throw new NamespaceException("Unregistrered prefix " + components[0]);
|
||||
}
|
||||
|
||||
String localName = components[1];
|
||||
|
||||
if ("*".equals(localName.trim()))
|
||||
{
|
||||
localName = ".*";
|
||||
}
|
||||
|
||||
Pattern.compile(uri);
|
||||
Pattern.compile(localName);
|
||||
|
||||
RegexQNamePattern qNamePattern = new RegexQNamePattern(uri,
|
||||
localName);
|
||||
|
||||
if (!qNamePattern.isMatch(QName.createQName(uri,
|
||||
components[1])))
|
||||
{
|
||||
throw new IllegalArgumentException("Illegal filters string " + filtersString
|
||||
+ " due to invalid regexp translatrion in " + filters[i] + " as " + qNamePattern);
|
||||
|
||||
}
|
||||
patterns.add(qNamePattern);
|
||||
}
|
||||
catch (NamespaceException e)
|
||||
{
|
||||
throw new IllegalArgumentException("Illegal filters string " + filtersString
|
||||
+ " due to unregistered name space in " + filters[i],
|
||||
e);
|
||||
}
|
||||
catch (PatternSyntaxException e)
|
||||
{
|
||||
throw new IllegalArgumentException("Illegal filters string " + filtersString
|
||||
+ " due to invalid regexp translatrion in " + filters[i],
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return patterns.toArray(new QNamePattern[] {});
|
||||
}
|
||||
|
||||
public void setQnameFilters(String filters)
|
||||
{
|
||||
ParameterCheck.mandatoryString("filters",
|
||||
filters);
|
||||
this.filters = filters;
|
||||
|
||||
resetFilters();
|
||||
}
|
||||
|
||||
public void setTemplatesPath(NodeRefExpression templatesPath)
|
||||
@@ -97,6 +223,8 @@ public class TypeVirtualizationMethod extends TemplateVirtualizationMethod
|
||||
public void setNamespacePrefixResolver(NamespacePrefixResolver resolver)
|
||||
{
|
||||
this.namespacePrefixResolver = resolver;
|
||||
|
||||
resetFilters();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,6 +257,19 @@ public class TypeVirtualizationMethod extends TemplateVirtualizationMethod
|
||||
return typeTemplateContentName + extension;
|
||||
}
|
||||
|
||||
private boolean isAnyFilterMatch(QName qname)
|
||||
{
|
||||
for (int i = 0; i < qnamePatternFilters.length; i++)
|
||||
{
|
||||
if (qnamePatternFilters[i].isMatch(qname))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private NodeRef templateNodeFor(ActualEnvironment env, NodeRef nodeRef)
|
||||
{
|
||||
try
|
||||
@@ -140,7 +281,7 @@ public class TypeVirtualizationMethod extends TemplateVirtualizationMethod
|
||||
}
|
||||
NodeRef templateNode = null;
|
||||
QName nodeType = env.getType(nodeRef);
|
||||
if (qnamePattern.isMatch(nodeType))
|
||||
if (isAnyFilterMatch(nodeType))
|
||||
{
|
||||
String typeTemplateNodeName = templateNodeNameForType(nodeType);
|
||||
|
||||
@@ -155,7 +296,7 @@ public class TypeVirtualizationMethod extends TemplateVirtualizationMethod
|
||||
for (QName aspect : aspects)
|
||||
{
|
||||
|
||||
if (qnamePattern.isMatch(aspect))
|
||||
if (isAnyFilterMatch(aspect))
|
||||
{
|
||||
String aspectTemplateNodeName = templateNodeNameForType(aspect);
|
||||
templateNode = env.getChildByName(templatesContainerNode,
|
||||
@@ -175,7 +316,8 @@ public class TypeVirtualizationMethod extends TemplateVirtualizationMethod
|
||||
}
|
||||
catch (PatternSyntaxException e)
|
||||
{
|
||||
logger.error("Invalid type methof type and aspect qName regexp pattern " + qnamePattern.toString());
|
||||
logger.error("Invalid type method type and aspect in qName filter ",
|
||||
e);
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@@ -61,6 +61,7 @@ import org.alfresco.repo.virtual.template.FilesFoldersConstraint;
|
||||
import org.alfresco.repo.virtual.template.FilingData;
|
||||
import org.alfresco.repo.virtual.template.FilingParameters;
|
||||
import org.alfresco.repo.virtual.template.FilingRule;
|
||||
import org.alfresco.repo.virtual.template.NamePatternPropertyValueConstraint;
|
||||
import org.alfresco.repo.virtual.template.PropertyValueConstraint;
|
||||
import org.alfresco.repo.virtual.template.NullFilingRule;
|
||||
import org.alfresco.repo.virtual.template.VirtualFolderDefinition;
|
||||
@@ -548,7 +549,7 @@ public class VirtualStoreImpl implements VirtualStore, VirtualFolderDefinitionRe
|
||||
}
|
||||
else
|
||||
{
|
||||
vqConstraint = new PropertyValueConstraint(new FilesFoldersConstraint(BasicConstraint.INSTANCE,
|
||||
vqConstraint = new NamePatternPropertyValueConstraint(new FilesFoldersConstraint(BasicConstraint.INSTANCE,
|
||||
true,
|
||||
true),
|
||||
ContentModel.PROP_NAME,
|
||||
|
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.virtual.template;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.service.cmr.search.SearchParameters;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.SearchLanguageConversion;
|
||||
|
||||
/**
|
||||
* Specifies a constraint on a property value, as for e.g.
|
||||
* ContentModel.PROP_NAME, to be applied as name pattern to queries given in the virtual folder
|
||||
* template.
|
||||
*
|
||||
*@author sdinuta
|
||||
*/
|
||||
public class NamePatternPropertyValueConstraint extends PropertyValueConstraint
|
||||
{
|
||||
private QName property;
|
||||
|
||||
private Serializable value;
|
||||
|
||||
private NamespacePrefixResolver nspResolver;
|
||||
|
||||
public NamePatternPropertyValueConstraint(VirtualQueryConstraint decoratedConstraint, QName property,
|
||||
Serializable value, NamespacePrefixResolver nspResolver)
|
||||
{
|
||||
super(decoratedConstraint,
|
||||
property,
|
||||
value,
|
||||
nspResolver);
|
||||
this.property = property;
|
||||
this.value = value;
|
||||
this.nspResolver = nspResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SearchParameters applyFTS(SearchParameters searchParameters)
|
||||
{
|
||||
String filePattern;
|
||||
StringBuffer luceneReserved = new StringBuffer();
|
||||
for(int i=0;i<value.toString().length();i++){
|
||||
if(SearchLanguageConversion.DEF_LUCENE.isReserved(value.toString().charAt(i))){
|
||||
luceneReserved.append(value.toString().charAt(i));
|
||||
}
|
||||
}
|
||||
String luceneReservedStr=luceneReserved.toString();
|
||||
String pattern =org.alfresco.util.ISO9075.encode(value.toString());
|
||||
for (int i = 0; i < luceneReservedStr.length(); i++)
|
||||
{
|
||||
pattern = pattern.replace(org.alfresco.util.ISO9075.encode(luceneReservedStr.substring(i,i + 1)),
|
||||
luceneReservedStr.substring(i,i + 1));
|
||||
}
|
||||
filePattern=SearchLanguageConversion.escapeForLucene(pattern);
|
||||
|
||||
SearchParameters constrainedParameters = searchParameters.copy();
|
||||
String theQuery = constrainedParameters.getQuery();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(" + theQuery + ")");
|
||||
sb.append(" and (");
|
||||
sb.append("TEXT:(").append(filePattern).append(") ");
|
||||
sb.append("or (");
|
||||
sb.append(" =").append(property.toPrefixString(this.nspResolver));
|
||||
sb.append(":").append(filePattern);
|
||||
sb.append(" ) ");
|
||||
sb.append(")");
|
||||
theQuery = sb.toString();
|
||||
constrainedParameters.setQuery(theQuery);
|
||||
|
||||
return constrainedParameters;
|
||||
}
|
||||
|
||||
}
|
@@ -72,7 +72,7 @@ public class PropertyValueConstraint extends VirtualQueryConstraintDecorator
|
||||
|
||||
}
|
||||
|
||||
private SearchParameters applyFTS(SearchParameters searchParameters)
|
||||
protected SearchParameters applyFTS(SearchParameters searchParameters)
|
||||
{
|
||||
SearchParameters constrainedParameters = searchParameters.copy();
|
||||
String theQuery = constrainedParameters.getQuery();
|
||||
@@ -80,7 +80,7 @@ public class PropertyValueConstraint extends VirtualQueryConstraintDecorator
|
||||
// TODO: introduce and use operator
|
||||
|
||||
theQuery = "(" + theQuery + ")" + " and " + "( " + "=" + property.toPrefixString(this.nspResolver) + ":"
|
||||
+ org.alfresco.util.ISO9075.encode(value.toString()) + " )";
|
||||
+"\""+value.toString() + "\" )";
|
||||
|
||||
constrainedParameters.setQuery(theQuery);
|
||||
|
||||
|
@@ -19,8 +19,6 @@
|
||||
|
||||
package org.alfresco.repo.virtual.template;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@@ -23,6 +23,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.search.EmptyResultSet;
|
||||
@@ -109,6 +110,12 @@ public class VirtualQueryImpl implements VirtualQuery
|
||||
constraint = new FilesFoldersConstraint(constraint,
|
||||
files,
|
||||
folders);
|
||||
if(pattern != null){
|
||||
constraint = new NamePatternPropertyValueConstraint(constraint,
|
||||
ContentModel.PROP_NAME,
|
||||
pattern,
|
||||
environment.getNamespacePrefixResolver());
|
||||
}
|
||||
constraint = new IgnoreConstraint(constraint,
|
||||
ignoreTypeQNames,
|
||||
ignoreAspectQNames);
|
||||
|
Reference in New Issue
Block a user