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:
@@ -162,6 +162,14 @@ virtual.folders.enabled=true
|
||||
virtual.folders.model=alfresco/model/virtualization-model.xml
|
||||
virtual.folders.model.labels=alfresco/messages/virtualization-model
|
||||
|
||||
#Virtual reference config
|
||||
|
||||
#virtual.reference.classpath.hash=${virtual.folders.config.vanilla.processor.classpath}->1,${virtual.folders.config.system.templates.classpath}->2
|
||||
|
||||
#Virtual store config
|
||||
|
||||
#Company home relative download associations of virtual entries
|
||||
#virtual.download.associations.folder=${spaces.dictionary.childname}/${spaces.virtualdownloads.childname}
|
||||
|
||||
#Generic virtualization methods config
|
||||
|
||||
@@ -174,17 +182,12 @@ virtual.folders.model.labels=alfresco/messages/virtualization-model
|
||||
|
||||
#System virtualization method aspect.
|
||||
#virtual.folders.config.system.aspect=vm:system-virtualization
|
||||
|
||||
#System virtualization method aspect defined template location property.
|
||||
#virtual.folders.config.system.aspect.template.location.property=vm:system-template-location
|
||||
|
||||
#Classpath to be explored for *.json entries defining system templates.
|
||||
#virtual.folders.config.system.templates.classpath=/org/alfresco/repo/virtual/node
|
||||
|
||||
#A company home relative name or qname path location of repository system templates.
|
||||
#virtual.folders.config.system.templates.path=Data Dictionary/Virtual Folder Template
|
||||
#virtual.folders.config.system.templates.path=${spaces.dictionary.childname}/${spaces.virtualfolders.childname}
|
||||
|
||||
#Content sub type of repository system templates.
|
||||
#virtual.folders.config.system.templates.template.type=vm:virtualFolderTemplate
|
||||
|
||||
@@ -201,4 +204,4 @@ virtual.folders.model.labels=alfresco/messages/virtualization-model
|
||||
#A company home relative name or qname path location of the type mapped templates.
|
||||
#virtual.folders.config.type.templates.path=${spaces.dictionary.childname}/${spaces.virtualfolders.childname}
|
||||
#Type and aspect qname regular expression filter.
|
||||
#virtual.folders.config.type.templates.qname.filter.regexp=\\{.*site/1\\.0\\}siteContainer|\\{.*claims_example/1.0\\}claimFolder
|
||||
#virtual.folders.config.type.templates.qname.filter.regexp=st:siteContainer,clex:claimFolder
|
@@ -1116,12 +1116,12 @@ cmis.disable.hidden.leading.period.files=false
|
||||
|
||||
#Virtual Folders Config Properties
|
||||
|
||||
virtual.folders.enabled=false
|
||||
virtual.folders.enabled=true
|
||||
virtual.folders.model=alfresco/model/virtualization-model.xml
|
||||
virtual.folders.model.labels=alfresco/messages/virtualization-model
|
||||
|
||||
#Virtual reference config
|
||||
|
||||
|
||||
virtual.reference.classpath.hash=${virtual.folders.config.vanilla.processor.classpath}->1,${virtual.folders.config.system.templates.classpath}->2
|
||||
|
||||
#Virtual store config
|
||||
@@ -1162,7 +1162,7 @@ virtual.folders.config.custom.aspect.template.association=vm:custom-template-ass
|
||||
#A company home relative name or qname path location of the type mapped templates.
|
||||
virtual.folders.config.type.templates.path=${spaces.dictionary.childname}/${spaces.virtualfolders.childname}
|
||||
#Type and aspect qname regular expression filter.
|
||||
virtual.folders.config.type.templates.qname.filter.regexp=\\{.*site/1\\.0\\}siteContainer
|
||||
virtual.folders.config.type.templates.qname.filter=none
|
||||
|
||||
# Preferred password encoding, md4, sha256, bcrypt10
|
||||
system.preferred.password.encoding=md4
|
||||
|
@@ -115,7 +115,7 @@
|
||||
<property name="path" value="${virtual.folders.config.type.templates.path}" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="qnameFilterRegexp" value="${virtual.folders.config.type.templates.qname.filter.regexp}" />
|
||||
<property name="qnameFilters" value="${virtual.folders.config.type.templates.qname.filter}" />
|
||||
</bean>
|
||||
|
||||
<bean id="virtualStore" class="org.alfresco.repo.virtual.store.VirtualStoreImpl">
|
||||
|
@@ -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);
|
||||
|
@@ -34,16 +34,16 @@ public class VirtualizationConfigTestBootstrap
|
||||
private NodeRefExpression downloadAssocaiationsFolder;
|
||||
|
||||
|
||||
private String typeTemplatesQNameFilterRegexp;
|
||||
private String typeTemplatesQNameFilter;
|
||||
|
||||
public void setTypeTemplatesQNameFilterRegexp(String typeTemplatesQNameFilterRegexp)
|
||||
public void setTypeTemplatesQNameFilter(String typeTemplatesQNameFilterRegexp)
|
||||
{
|
||||
this.typeTemplatesQNameFilterRegexp = typeTemplatesQNameFilterRegexp;
|
||||
this.typeTemplatesQNameFilter = typeTemplatesQNameFilterRegexp;
|
||||
}
|
||||
|
||||
public String getTypeTemplatesQNameFilterRegexp()
|
||||
public String getTypeTemplatesQNameFilter()
|
||||
{
|
||||
return this.typeTemplatesQNameFilterRegexp;
|
||||
return this.typeTemplatesQNameFilter;
|
||||
}
|
||||
|
||||
public void setTypeTemplatesPath(NodeRefExpression typeTemplatesPath)
|
||||
|
@@ -38,7 +38,6 @@ import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.forms.FormData;
|
||||
import org.alfresco.repo.forms.Item;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.node.integrity.IntegrityChecker;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
@@ -53,6 +52,7 @@ import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -129,45 +129,73 @@ public abstract class VirtualizationIntegrationTest extends TestCase implements
|
||||
|
||||
protected static final ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS);
|
||||
|
||||
protected ContentService contentService;
|
||||
|
||||
private TransactionService transactionService;
|
||||
|
||||
protected FileInfo testRootFolder;
|
||||
|
||||
protected FileFolderService fileAndFolderService;
|
||||
|
||||
protected ActualEnvironment environment;
|
||||
protected ContentService contentService;
|
||||
|
||||
protected NodeRef virtualFolder1NodeRef;
|
||||
protected TransactionService transactionService;
|
||||
|
||||
protected NodeService nodeService;
|
||||
|
||||
protected PermissionService permissionService;
|
||||
|
||||
protected SearchService searchService;
|
||||
|
||||
protected RetryingTransactionHelper retryingTransactionHelper;
|
||||
|
||||
protected FileInfo testRootFolder;
|
||||
|
||||
protected NodeRef virtualFolder1NodeRef;
|
||||
|
||||
protected NodeRef rootNodeRef;
|
||||
|
||||
protected ActualEnvironment environment;
|
||||
|
||||
protected TypeAndAspectsFormProcessor typeAndAspectsFormProcessor;
|
||||
|
||||
private UserTransaction txn;
|
||||
|
||||
protected AuthenticationComponent authenticationComponent;
|
||||
|
||||
protected PermissionService permissionService;
|
||||
|
||||
/** The root node reference */
|
||||
protected NodeRef rootNodeRef;
|
||||
|
||||
protected VirtualizationConfigTestBootstrap virtualizationConfigTestBootstrap;
|
||||
|
||||
protected String configuredTemplatesClassPath = null;
|
||||
|
||||
protected SystemTemplateLocationsConstraint constraints;
|
||||
|
||||
/** when set to a not-null value will be restored up[on {@link #tearDown()} */
|
||||
protected String configuredTemplatesClassPath = null;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
virtualizationConfigTestBootstrap = ctx.getBean(VIRTUALIZATION_CONFIG_TEST_BOOTSTRAP_BEAN_ID,
|
||||
VirtualizationConfigTestBootstrap.class);
|
||||
|
||||
// Get the required services
|
||||
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
|
||||
|
||||
transactionService = serviceRegistry.getTransactionService();
|
||||
retryingTransactionHelper = serviceRegistry.getRetryingTransactionHelper();
|
||||
nodeService = serviceRegistry.getNodeService();
|
||||
contentService = serviceRegistry.getContentService();
|
||||
fileAndFolderService = serviceRegistry.getFileFolderService();
|
||||
permissionService = serviceRegistry.getPermissionService();
|
||||
searchService=serviceRegistry.getSearchService();
|
||||
|
||||
authenticationComponent = ctx.getBean("authenticationComponent",
|
||||
AuthenticationComponent.class);
|
||||
|
||||
environment = ctx.getBean("actualEnvironment",
|
||||
ActualEnvironment.class);
|
||||
|
||||
typeAndAspectsFormProcessor = ctx.getBean("typeAndAspectsFormProcessor",
|
||||
TypeAndAspectsFormProcessor.class);
|
||||
|
||||
constraints = ctx.getBean("systemTemplateLocations",
|
||||
SystemTemplateLocationsConstraint.class);
|
||||
|
||||
Repository repository = ctx.getBean("repositoryHelper",
|
||||
Repository.class);
|
||||
|
||||
if (!virtualizationConfigTestBootstrap.areVirtualFoldersEnabled())
|
||||
{
|
||||
// "use the force" and enable virtual folders
|
||||
@@ -180,23 +208,7 @@ public abstract class VirtualizationIntegrationTest extends TestCase implements
|
||||
logger.info("Virtual folders are spring-enabled.");
|
||||
}
|
||||
|
||||
// Get the required services
|
||||
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
|
||||
transactionService = serviceRegistry.getTransactionService();
|
||||
authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
|
||||
retryingTransactionHelper = (RetryingTransactionHelper) ctx.getBean("retryingTransactionHelper");
|
||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||
permissionService = (PermissionService) ctx.getBean("PermissionService");
|
||||
|
||||
contentService = ctx.getBean("contentService",
|
||||
ContentService.class);
|
||||
environment = ctx.getBean("actualEnvironment",
|
||||
ActualEnvironment.class);
|
||||
|
||||
fileAndFolderService = serviceRegistry.getFileFolderService();
|
||||
|
||||
Repository repository = ctx.getBean("repositoryHelper",
|
||||
Repository.class);
|
||||
|
||||
// start the transaction
|
||||
txn = transactionService.getUserTransaction();
|
||||
@@ -207,12 +219,6 @@ public abstract class VirtualizationIntegrationTest extends TestCase implements
|
||||
testRootFolder = fileAndFolderService.create(root,
|
||||
TEST_ROOT_FOLDER_NAME,
|
||||
ContentModel.TYPE_FOLDER);
|
||||
nodeService = ctx.getBean("nodeService",
|
||||
NodeService.class);
|
||||
typeAndAspectsFormProcessor = ctx.getBean("typeAndAspectsFormProcessor",
|
||||
TypeAndAspectsFormProcessor.class);
|
||||
constraints = ctx.getBean("systemTemplateLocations",
|
||||
SystemTemplateLocationsConstraint.class);
|
||||
|
||||
virtualFolder1NodeRef = createVirtualizedFolder(testRootFolder.getNodeRef(),
|
||||
VIRTUAL_FOLDER_1_NAME,
|
||||
|
@@ -38,15 +38,12 @@ import org.alfresco.repo.virtual.store.VirtualStoreImplTest;
|
||||
import org.alfresco.repo.virtual.template.ApplyTemplateMethodTest;
|
||||
import org.alfresco.repo.virtual.template.TemplateFilingRuleTest;
|
||||
import org.alfresco.repo.virtual.template.TemplateResourceProcessorTest;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Bogdan Horje
|
||||
*/
|
||||
public class VirtualizationIntegrationTestSuite extends TestSuite implements VirtualizationTest
|
||||
{
|
||||
protected static final ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS);
|
||||
|
||||
public static Test suite()
|
||||
{
|
||||
@@ -62,7 +59,7 @@ public class VirtualizationIntegrationTestSuite extends TestSuite implements Vir
|
||||
suite.addTest(new JUnit4TestAdapter(ApplyTemplateMethodTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(SystemTemplateLocationsConstraintTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(SystemVirtualizationMethodTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(TypeVirtualizationMethodTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(TypeVirtualizationMethodTest.Integration.class));
|
||||
suite.addTest(new JUnit4TestAdapter(TemplateResourceProcessorTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(VirtualStoreImplTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(NodeRefPathExpressionTest.class));
|
||||
|
@@ -43,5 +43,6 @@ public class VirtualizationUnitTestSuite
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.virtual.ref.StoredPathHasherTest.class));
|
||||
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.virtual.template.VirtualQueryImplTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.virtual.store.TypeVirtualizationMethodTest.Unit.class));
|
||||
}
|
||||
}
|
||||
|
@@ -29,11 +29,14 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.CannedQueryPageDetails;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.virtual.VirtualizationIntegrationTest;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -45,6 +48,7 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra
|
||||
{
|
||||
|
||||
private static final String NEW_FILE_NAME_2 = "RenameTest2";
|
||||
|
||||
private static final String NEW_FILE_NAME_1 = "RenamedTest";
|
||||
|
||||
@Test
|
||||
@@ -126,22 +130,9 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"Node2");
|
||||
|
||||
HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();
|
||||
properties.put(ContentModel.PROP_NAME,
|
||||
"testfile.txt");
|
||||
QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||
QName.createValidLocalName("testfile.txt"));
|
||||
|
||||
nodeService.createNode(node1,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
assocQName,
|
||||
ContentModel.TYPE_CONTENT,
|
||||
properties);
|
||||
nodeService.createNode(node2,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
assocQName,
|
||||
ContentModel.TYPE_CONTENT,
|
||||
properties);
|
||||
String fileName="testfile.txt";
|
||||
fileAndFolderService.create(node1, fileName, ContentModel.TYPE_CONTENT);
|
||||
fileAndFolderService.create(node2, fileName, ContentModel.TYPE_CONTENT);
|
||||
|
||||
List<FileInfo> search = fileAndFolderService.search(virtualFolder1NodeRef,
|
||||
"testfile.txt",
|
||||
@@ -298,14 +289,14 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra
|
||||
contentName);
|
||||
|
||||
{
|
||||
PagingResults<FileInfo> folderChildren = fileAndFolderService
|
||||
.list(node2,
|
||||
false,
|
||||
true,
|
||||
"*",
|
||||
Collections.<QName> emptySet(),
|
||||
Collections.<Pair<QName, Boolean>> emptyList(),
|
||||
new PagingRequest(100));
|
||||
PagingResults<FileInfo> folderChildren = fileAndFolderService.list(node2,
|
||||
false,
|
||||
true,
|
||||
"*",
|
||||
Collections.<QName> emptySet(),
|
||||
Collections
|
||||
.<Pair<QName, Boolean>> emptyList(),
|
||||
new PagingRequest(100));
|
||||
List<FileInfo> page = folderChildren.getPage();
|
||||
assertContainsNames(page,
|
||||
folderName);
|
||||
@@ -314,14 +305,14 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra
|
||||
}
|
||||
|
||||
{
|
||||
PagingResults<FileInfo> contentChildren = fileAndFolderService
|
||||
.list(node2,
|
||||
true,
|
||||
false,
|
||||
"*",
|
||||
Collections.<QName> emptySet(),
|
||||
Collections.<Pair<QName, Boolean>> emptyList(),
|
||||
new PagingRequest(100));
|
||||
PagingResults<FileInfo> contentChildren = fileAndFolderService.list(node2,
|
||||
true,
|
||||
false,
|
||||
"*",
|
||||
Collections.<QName> emptySet(),
|
||||
Collections
|
||||
.<Pair<QName, Boolean>> emptyList(),
|
||||
new PagingRequest(100));
|
||||
List<FileInfo> page = contentChildren.getPage();
|
||||
assertMissesNames(page,
|
||||
folderName);
|
||||
@@ -403,7 +394,7 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra
|
||||
NodeRef childByName = nodeService.getChildByName(node2,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
contentName);
|
||||
//rename file in virtual context
|
||||
// rename file in virtual context
|
||||
FileInfo renamedFileInfo = fileAndFolderService.rename(childByName,
|
||||
NEW_FILE_NAME_1);
|
||||
assertNotNull(renamedFileInfo);
|
||||
@@ -417,13 +408,13 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
contentName));
|
||||
assertNotNull(nodeService.getChildByName(node2,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
NEW_FILE_NAME_1));
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
NEW_FILE_NAME_1));
|
||||
assertNotNull(nodeService.getChildByName(vf,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
NEW_FILE_NAME_1));
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
NEW_FILE_NAME_1));
|
||||
|
||||
//rename physical file
|
||||
// rename physical file
|
||||
childByName = nodeService.getChildByName(vf,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
NEW_FILE_NAME_1);
|
||||
@@ -447,4 +438,181 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra
|
||||
NEW_FILE_NAME_2));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListNamePattern() throws Exception
|
||||
{
|
||||
List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>(1);
|
||||
sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_NAME,
|
||||
false));
|
||||
String name = "A N.&ame.txt";
|
||||
String name1 = "A N.&ame-1.txt";
|
||||
String nameAfter = "XXName.txt";
|
||||
|
||||
NodeRef vf = createVirtualizedFolder(testRootFolder.getNodeRef(),
|
||||
"TestVirtualFileFolderService_testVirtualFolderVirtualChild",
|
||||
TEST_TEMPLATE_3_JSON_SYS_PATH);
|
||||
NodeRef node1 = nodeService.getChildByName(vf,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"Node1");
|
||||
createContent(node1,
|
||||
name,
|
||||
"0",
|
||||
MimetypeMap.MIMETYPE_TEXT_PLAIN,
|
||||
"UTF-8");
|
||||
|
||||
createContent(node1,
|
||||
name1,
|
||||
"01",
|
||||
MimetypeMap.MIMETYPE_TEXT_PLAIN,
|
||||
"UTF-8");
|
||||
|
||||
createContent(node1,
|
||||
nameAfter,
|
||||
"1",
|
||||
MimetypeMap.MIMETYPE_TEXT_PLAIN,
|
||||
"UTF-8");
|
||||
|
||||
String namePattern = "A N.&ame*.txt";
|
||||
PagingResults<FileInfo> results = fileAndFolderService.list(node1,
|
||||
true,
|
||||
false,
|
||||
namePattern,
|
||||
null,
|
||||
sortProps,
|
||||
new PagingRequest(CannedQueryPageDetails.DEFAULT_PAGE_SIZE));
|
||||
|
||||
List<FileInfo> page = results.getPage();
|
||||
assertEquals(2,
|
||||
page.size());
|
||||
assertEquals(page.get(0).getName(),
|
||||
name1);
|
||||
assertEquals(page.get(1).getName(),
|
||||
name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastDuplicate() throws Exception
|
||||
{
|
||||
NodeRef lastDup = null;
|
||||
List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>(1);
|
||||
sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_NAME,
|
||||
false));
|
||||
String name = "AName.txt";
|
||||
String nameAfter = "XXName.txt";
|
||||
|
||||
NodeRef vf = createVirtualizedFolder(testRootFolder.getNodeRef(),
|
||||
"TestVirtualFileFolderService_testVirtualFolderVirtualChild",
|
||||
TEST_TEMPLATE_3_JSON_SYS_PATH);
|
||||
NodeRef node1 = nodeService.getChildByName(vf,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"Node1");
|
||||
createContent(node1,
|
||||
name,
|
||||
"0",
|
||||
MimetypeMap.MIMETYPE_TEXT_PLAIN,
|
||||
"UTF-8");
|
||||
NodeRef aNameNodeRef = nodeService.getChildByName(node1,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
name);
|
||||
|
||||
createContent(node1,
|
||||
nameAfter,
|
||||
"1",
|
||||
MimetypeMap.MIMETYPE_TEXT_PLAIN,
|
||||
"UTF-8");
|
||||
NodeRef nameAfterNodeRef = nodeService.getChildByName(node1,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
nameAfter);
|
||||
|
||||
String namePattern = addWildCardInName(name,
|
||||
fileAndFolderService
|
||||
.getFileInfo(aNameNodeRef)
|
||||
.getContentData()
|
||||
.getMimetype());
|
||||
PagingResults<FileInfo> results = fileAndFolderService
|
||||
.list(nodeService.getPrimaryParent(aNameNodeRef).getParentRef(),
|
||||
true,
|
||||
false,
|
||||
namePattern,
|
||||
null,
|
||||
sortProps,
|
||||
new PagingRequest(CannedQueryPageDetails.DEFAULT_PAGE_SIZE));
|
||||
|
||||
List<FileInfo> page = results.getPage();
|
||||
FileInfo fileInfo = null;
|
||||
if (page.size() > 0)
|
||||
{
|
||||
fileInfo = page.get(0);
|
||||
lastDup = fileInfo.getNodeRef();
|
||||
}
|
||||
assertFalse(lastDup.equals(nameAfterNodeRef));
|
||||
}
|
||||
|
||||
private String addWildCardInName(String name, String mimetype)
|
||||
{
|
||||
MimetypeService mimetypeService = ctx.getBean("mimetypeService",
|
||||
MimetypeService.class);
|
||||
String extension = mimetypeService.getExtension(mimetype);
|
||||
return name.substring(0,
|
||||
name.length() - (extension.length() + 1))
|
||||
.concat("*." + extension);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListUsedWithCMIS() throws Exception
|
||||
{
|
||||
NodeRef vf = createVirtualizedFolder(testRootFolder.getNodeRef(),
|
||||
"TestVirtualFileFolderService_testVirtualFolderVirtualChild",
|
||||
TEST_TEMPLATE_3_JSON_SYS_PATH);
|
||||
NodeRef node2 = nodeService.getChildByName(vf,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"Node2");
|
||||
String contentName = "ContentVirtualChild";
|
||||
createContent(node2,
|
||||
contentName);
|
||||
|
||||
NodeRef childByName = nodeService.getChildByName(node2,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
contentName);
|
||||
|
||||
FileInfo renamedFileInfo = fileAndFolderService.rename(childByName,
|
||||
NEW_FILE_NAME_1);
|
||||
assertNotNull(renamedFileInfo);
|
||||
assertEquals(NEW_FILE_NAME_1,
|
||||
nodeService.getProperty(childByName,
|
||||
ContentModel.PROP_NAME));
|
||||
|
||||
List<Pair<QName, Boolean>> sortProps = Collections.<Pair<QName, Boolean>> emptyList();
|
||||
PagingRequest pagingRequest = new PagingRequest(100);
|
||||
|
||||
PagingResults<FileInfo> results = fileAndFolderService.list(vf,
|
||||
true,
|
||||
true,
|
||||
null,
|
||||
sortProps,
|
||||
pagingRequest);
|
||||
|
||||
assertNotNull(results);
|
||||
|
||||
assertEquals(3,
|
||||
results.getPage().size());
|
||||
|
||||
String contentName1 = "ContentVirtualChild";
|
||||
createContent(node2,
|
||||
contentName1);
|
||||
|
||||
results = fileAndFolderService.list(vf,
|
||||
true,
|
||||
true,
|
||||
null,
|
||||
sortProps,
|
||||
pagingRequest);
|
||||
|
||||
assertNotNull(results);
|
||||
|
||||
assertEquals(4,
|
||||
results.getPage().size());
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -19,8 +19,6 @@
|
||||
|
||||
package org.alfresco.repo.virtual.bundle;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -36,6 +34,7 @@ import org.alfresco.repo.download.DownloadModel;
|
||||
import org.alfresco.repo.download.DownloadStorage;
|
||||
import org.alfresco.repo.node.integrity.IntegrityChecker;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.repo.virtual.VirtualContentModel;
|
||||
import org.alfresco.repo.virtual.VirtualizationIntegrationTest;
|
||||
import org.alfresco.repo.virtual.config.NodeRefExpression;
|
||||
@@ -49,7 +48,6 @@ import org.alfresco.repo.virtual.store.VirtualStore;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.CopyService;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.Path;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
@@ -127,9 +125,9 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe
|
||||
"shouldNotBeCreated");
|
||||
fail("Should not be able to create node in a readonly context.");
|
||||
}
|
||||
catch (InvalidNodeRefException e)
|
||||
catch (AccessDeniedException e)
|
||||
{
|
||||
logger.info("Succesfully denied creation in readonl",
|
||||
logger.info("Succesfully denied creation in readonly",
|
||||
e);
|
||||
}
|
||||
}
|
||||
@@ -210,37 +208,29 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe
|
||||
"Node2");
|
||||
assertNotNull(secondChild);
|
||||
|
||||
HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();
|
||||
properties.put(ContentModel.PROP_NAME,
|
||||
"testfile.txt");
|
||||
QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||
QName.createValidLocalName("testfile.txt"));
|
||||
authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
||||
// add testfile.txt to first virtual child
|
||||
|
||||
createNode(firstChild,
|
||||
assocQName,
|
||||
properties);
|
||||
String fileName="testfile.txt";
|
||||
uploadNode(firstChild,
|
||||
fileName);
|
||||
assertNotNull(nodeService.getChildByName(firstChild.toNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"testfile.txt"));
|
||||
createNode(firstChild,
|
||||
assocQName,
|
||||
properties);
|
||||
uploadNode(firstChild,
|
||||
fileName);
|
||||
assertNotNull(nodeService.getChildByName(firstChild.toNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"testfile-1.txt"));
|
||||
|
||||
// add testfile.txt to second virtual child
|
||||
createNode(secondChild,
|
||||
assocQName,
|
||||
properties);
|
||||
uploadNode(secondChild,
|
||||
fileName);
|
||||
assertNotNull(nodeService.getChildByName(secondChild.toNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"testfile-2.txt"));
|
||||
createNode(secondChild,
|
||||
assocQName,
|
||||
properties);
|
||||
uploadNode(secondChild,
|
||||
fileName);
|
||||
assertNotNull(nodeService.getChildByName(secondChild.toNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"testfile-3.txt"));
|
||||
@@ -248,13 +238,9 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe
|
||||
// add again to first virtual child starting from the last index found
|
||||
// (this is the index that comes from
|
||||
// upload-post.js)
|
||||
properties.put(ContentModel.PROP_NAME,
|
||||
"testfile-2.txt");
|
||||
assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||
QName.createValidLocalName("testfile-2.txt"));
|
||||
createNode(firstChild,
|
||||
assocQName,
|
||||
properties);
|
||||
fileName="testfile-2.txt";
|
||||
uploadNode(firstChild,
|
||||
fileName);
|
||||
assertNotNull(nodeService.getChildByName(firstChild.toNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"testfile-4.txt"));
|
||||
@@ -262,28 +248,14 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe
|
||||
// test create node for actual node starting from the last index found
|
||||
// (this is the index that comes from
|
||||
// upload-post.js)
|
||||
properties.put(ContentModel.PROP_NAME,
|
||||
"testfile-5.txt");
|
||||
assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||
QName.createValidLocalName("testfile-5.txt"));
|
||||
nodeService.createNode(virtualFolder1NodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
assocQName,
|
||||
ContentModel.TYPE_CONTENT,
|
||||
properties).getChildRef();
|
||||
fileName="testfile-5.txt";
|
||||
fileAndFolderService.create(virtualFolder1NodeRef, fileName, ContentModel.TYPE_CONTENT);
|
||||
assertNotNull(nodeService.getChildByName(virtualFolder1NodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"testfile-5.txt"));
|
||||
|
||||
properties.put(ContentModel.PROP_NAME,
|
||||
"testfile-6.txt");
|
||||
assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||
QName.createValidLocalName("testfile-6.txt"));
|
||||
nodeService.createNode(virtualFolder1NodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
assocQName,
|
||||
ContentModel.TYPE_CONTENT,
|
||||
properties).getChildRef();
|
||||
fileName="testfile-6.txt";
|
||||
fileAndFolderService.create(virtualFolder1NodeRef, fileName, ContentModel.TYPE_CONTENT);
|
||||
assertNotNull(nodeService.getChildByName(virtualFolder1NodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"testfile-6.txt"));
|
||||
@@ -291,38 +263,20 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe
|
||||
// add again to second child starting from the last index found (this is
|
||||
// the index that comes from
|
||||
// upload-post.js)
|
||||
properties.put(ContentModel.PROP_NAME,
|
||||
"testfile-4.txt");
|
||||
assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||
QName.createValidLocalName("testfile-4.txt"));
|
||||
nodeService.createNode(secondChild.toNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
assocQName,
|
||||
ContentModel.TYPE_CONTENT,
|
||||
properties).getChildRef();
|
||||
fileName="testfile-4.txt";
|
||||
uploadNode(secondChild,
|
||||
fileName);
|
||||
assertNotNull(nodeService.getChildByName(secondChild.toNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"testfile-7.txt"));
|
||||
|
||||
// test situation when file name is of form testfile1-1.txt
|
||||
properties.put(ContentModel.PROP_NAME,
|
||||
"testfile1-1.txt");
|
||||
assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||
QName.createValidLocalName("testfile1-1.txt"));
|
||||
nodeService.createNode(secondChild.toNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
assocQName,
|
||||
ContentModel.TYPE_CONTENT,
|
||||
properties).getChildRef();
|
||||
fileName="testfile1-1.txt";
|
||||
fileAndFolderService.create(secondChild.toNodeRef(), fileName, ContentModel.TYPE_CONTENT);
|
||||
assertNotNull(nodeService.getChildByName(secondChild.toNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"testfile1-1.txt"));
|
||||
|
||||
nodeService.createNode(secondChild.toNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
assocQName,
|
||||
ContentModel.TYPE_CONTENT,
|
||||
properties).getChildRef();
|
||||
fileAndFolderService.create(secondChild.toNodeRef(), fileName, ContentModel.TYPE_CONTENT);
|
||||
assertNotNull(nodeService.getChildByName(secondChild.toNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"testfile1-1-1.txt"));
|
||||
@@ -393,6 +347,13 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe
|
||||
childAssocsRef);
|
||||
}
|
||||
|
||||
private void uploadNode(Reference reference, String name)
|
||||
{
|
||||
fileAndFolderService.create(reference.toNodeRef(),
|
||||
name,
|
||||
ContentModel.TYPE_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assets that the given {@link ChildAssociationRef} was created within the
|
||||
* given virtualizable nodeRef container reference.
|
||||
@@ -452,18 +413,10 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"Node2");
|
||||
|
||||
HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();
|
||||
properties.put(ContentModel.PROP_NAME,
|
||||
"testfile.txt");
|
||||
QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||
QName.createValidLocalName("testfile.txt"));
|
||||
String fileName="testfile.txt";
|
||||
|
||||
// add testfile.txt to first virtual child
|
||||
nodeService.createNode(node2,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
assocQName,
|
||||
ContentModel.TYPE_CONTENT,
|
||||
properties);
|
||||
fileAndFolderService.create(node2, fileName, ContentModel.TYPE_CONTENT);
|
||||
|
||||
NodeRef childRef = nodeService.getChildByName(node2,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
@@ -487,11 +440,7 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe
|
||||
"Node2_1");
|
||||
assertNotNull(node2_1);
|
||||
|
||||
nodeService.createNode(node2_1,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
assocQName,
|
||||
ContentModel.TYPE_CONTENT,
|
||||
properties);
|
||||
fileAndFolderService.create(node2_1, fileName, ContentModel.TYPE_CONTENT);
|
||||
|
||||
NodeRef childRef_1 = nodeService.getChildByName(node2_1,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
@@ -1200,6 +1149,110 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe
|
||||
assertNotNull(childFolderNodeRef);
|
||||
}
|
||||
|
||||
public void testChildByName_ACE_4700() throws Exception
|
||||
{
|
||||
NodeRef node1 = nodeService.getChildByName(virtualFolder1NodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"Node1");
|
||||
assertNotNull(node1);
|
||||
String filename = "2015-11_11_1557_folder_empty_space.txt";
|
||||
fileAndFolderService.create(node1,
|
||||
filename,
|
||||
ContentModel.TYPE_CONTENT);
|
||||
fileAndFolderService.create(node1,
|
||||
filename,
|
||||
ContentModel.TYPE_CONTENT);
|
||||
assertNotNull(nodeService.getChildByName(node1,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"2015-11_11_1557_folder_empty_space.txt"));
|
||||
assertNotNull(nodeService.getChildByName(node1,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"2015-11_11_1557_folder_empty_space-1.txt"));
|
||||
assertNull(nodeService.getChildByName(node1,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"2015-11_11_1557_folder_empty_space-2.txt"));
|
||||
|
||||
String suportedCharsFileName = "file~!@#$%^&-=+][';.,.txt";
|
||||
String suportedCharsFileName1 = "file~!@#$%^&-=+][';.,-1.txt";
|
||||
String suportedCharsFileName2 = "file~!@#$%^&-=+][';.,-2.txt";
|
||||
fileAndFolderService.create(node1,
|
||||
suportedCharsFileName,
|
||||
ContentModel.TYPE_CONTENT);
|
||||
fileAndFolderService.create(node1,
|
||||
suportedCharsFileName,
|
||||
ContentModel.TYPE_CONTENT);
|
||||
assertNotNull(nodeService.getChildByName(node1,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
suportedCharsFileName));
|
||||
assertNotNull(nodeService.getChildByName(node1,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
suportedCharsFileName1));
|
||||
assertNull(nodeService.getChildByName(node1,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
suportedCharsFileName2));
|
||||
}
|
||||
|
||||
public void testHasAspect() throws Exception
|
||||
{
|
||||
// test for virtual folder
|
||||
NodeRef node1 = nodeService.getChildByName(virtualFolder1NodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"Node1");
|
||||
assertNotNull(node1);
|
||||
assertTrue(nodeService.hasAspect(node1,
|
||||
VirtualContentModel.ASPECT_VIRTUAL));
|
||||
assertFalse(nodeService.hasAspect(node1,
|
||||
VirtualContentModel.ASPECT_VIRTUAL_DOCUMENT));
|
||||
|
||||
// test for document in virtual context
|
||||
String filename = "testName.txt";
|
||||
NodeRef fileNodeRef = fileAndFolderService.create(node1,
|
||||
filename,
|
||||
ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
assertFalse(nodeService.hasAspect(fileNodeRef,
|
||||
VirtualContentModel.ASPECT_VIRTUAL));
|
||||
assertTrue(nodeService.hasAspect(fileNodeRef,
|
||||
VirtualContentModel.ASPECT_VIRTUAL_DOCUMENT));
|
||||
|
||||
// test for folder in virtual context
|
||||
createFolder(testRootFolder.getNodeRef(),
|
||||
"FOLDER").getChildRef();
|
||||
NodeRef virtualFolder = createVirtualizedFolder(testRootFolder.getNodeRef(),
|
||||
VIRTUAL_FOLDER_2_NAME,
|
||||
TEST_TEMPLATE_6_JSON_SYS_PATH);
|
||||
NodeRef node1_1 = nodeService.getChildByName(virtualFolder,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"Node1");
|
||||
assertNotNull(node1_1);
|
||||
|
||||
NodeRef physicalFolderInVirtualContext = nodeService.getChildByName(node1_1,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"FOLDER");
|
||||
assertNotNull(physicalFolderInVirtualContext);
|
||||
|
||||
assertFalse(nodeService.hasAspect(physicalFolderInVirtualContext,
|
||||
VirtualContentModel.ASPECT_VIRTUAL));
|
||||
assertTrue(nodeService.hasAspect(physicalFolderInVirtualContext,
|
||||
VirtualContentModel.ASPECT_VIRTUAL_DOCUMENT));
|
||||
|
||||
//test the document created in a folder in virtual context
|
||||
createContent(physicalFolderInVirtualContext,
|
||||
"testFile1",
|
||||
"0",
|
||||
MimetypeMap.MIMETYPE_TEXT_PLAIN,
|
||||
"UTF-8");
|
||||
|
||||
NodeRef childFileNodeRef = nodeService.getChildByName(physicalFolderInVirtualContext,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
"testFile1");
|
||||
assertNotNull(childFileNodeRef);
|
||||
assertFalse(nodeService.hasAspect(childFileNodeRef,
|
||||
VirtualContentModel.ASPECT_VIRTUAL));
|
||||
assertFalse(nodeService.hasAspect(childFileNodeRef,
|
||||
VirtualContentModel.ASPECT_VIRTUAL_DOCUMENT));
|
||||
|
||||
}
|
||||
|
||||
private NodeRef createDownloadNode()
|
||||
{
|
||||
NodeRef createDownloadNode = downloadStorage.createDownloadNode(true);
|
||||
|
@@ -1,11 +1,35 @@
|
||||
/*
|
||||
* 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.store;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.JUnit4TestAdapter;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.site.SiteModel;
|
||||
import org.alfresco.repo.virtual.VirtualizationIntegrationTest;
|
||||
@@ -23,218 +47,348 @@ import org.alfresco.repo.virtual.ref.ResourceProcessor;
|
||||
import org.alfresco.repo.virtual.ref.VanillaProtocol;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceException;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.junit.Test;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.internal.stubbing.answers.ThrowsException;
|
||||
|
||||
public class TypeVirtualizationMethodTest extends VirtualizationIntegrationTest
|
||||
public class TypeVirtualizationMethodTest extends TestSuite
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(TypeVirtualizationMethodTest.class);
|
||||
|
||||
private static final QName TEST_FOLDER_TYPE = SiteModel.TYPE_SITE;
|
||||
|
||||
private static final QName TEST_ASPECT = SiteModel.ASPECT_SITE_CONTAINER;
|
||||
|
||||
private TypeVirtualizationMethod typeVirtualizationMethod;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
public static class Integration extends VirtualizationIntegrationTest
|
||||
{
|
||||
super.setUp();
|
||||
typeVirtualizationMethod = ctx.getBean("typeVirtualizationMethod",
|
||||
TypeVirtualizationMethod.class);
|
||||
}
|
||||
private TypeVirtualizationMethod typeVirtualizationMethod;
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
typeVirtualizationMethod.setQnameFilterRegexp(virtualizationConfigTestBootstrap
|
||||
.getTypeTemplatesQNameFilterRegexp());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegExpFiltering() throws Exception
|
||||
{
|
||||
typeVirtualizationMethod.setQnameFilterRegexp("\\{.*site/1\\.0\\}site");
|
||||
|
||||
ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(),
|
||||
"TypeVirtualized",
|
||||
TEST_FOLDER_TYPE);
|
||||
assertFalse(typeVirtualizationMethod.canVirtualize(environment,
|
||||
typedNodeAssocRef.getChildRef()));
|
||||
|
||||
addTypeTemplate(TEST_FOLDER_TYPE,
|
||||
TEST_TEMPLATE_1_JS_CLASSPATH);
|
||||
|
||||
assertTrue(typeVirtualizationMethod.canVirtualize(environment,
|
||||
typedNodeAssocRef.getChildRef()));
|
||||
|
||||
|
||||
typeVirtualizationMethod.setQnameFilterRegexp("\\{.*site/2\\.0\\}site");
|
||||
|
||||
assertFalse(typeVirtualizationMethod.canVirtualize(environment,
|
||||
typedNodeAssocRef.getChildRef()));
|
||||
|
||||
//invalid regexp
|
||||
typeVirtualizationMethod.setQnameFilterRegexp("{.*site/1\\.0\\}site");
|
||||
|
||||
assertFalse(typeVirtualizationMethod.canVirtualize(environment,
|
||||
typedNodeAssocRef.getChildRef()));
|
||||
|
||||
}
|
||||
|
||||
public void testVirtualizeCmFolder_recusive() throws Exception
|
||||
{
|
||||
ChildAssociationRef templateContentChildRef = addTypeTemplate(ContentModel.TYPE_FOLDER,
|
||||
TEST_TEMPLATE_1_JS_CLASSPATH);
|
||||
virtualize(templateContentChildRef.getChildRef(),
|
||||
ContentModel.TYPE_FOLDER);
|
||||
}
|
||||
|
||||
public void testCanVirtualize() throws Exception
|
||||
{
|
||||
ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(),
|
||||
"TypeVirtualized",
|
||||
TEST_FOLDER_TYPE);
|
||||
NodeRef typeNode = typedNodeAssocRef.getChildRef();
|
||||
|
||||
assertFalse(typeVirtualizationMethod.canVirtualize(environment,
|
||||
typeNode));
|
||||
|
||||
addTypeTemplate(TEST_FOLDER_TYPE,
|
||||
TEST_TEMPLATE_1_JS_CLASSPATH);
|
||||
|
||||
assertTrue(typeVirtualizationMethod.canVirtualize(environment,
|
||||
typeNode));
|
||||
|
||||
}
|
||||
|
||||
public void testCanVirtualizeAspect() throws Exception
|
||||
{
|
||||
ChildAssociationRef aspectNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(),
|
||||
"TypeVirtualized",
|
||||
ContentModel.TYPE_FOLDER);
|
||||
NodeRef aspectNode = aspectNodeAssocRef.getChildRef();
|
||||
|
||||
nodeService.addAspect(aspectNode,
|
||||
TEST_ASPECT,
|
||||
Collections.<QName, Serializable> emptyMap());
|
||||
|
||||
assertFalse(typeVirtualizationMethod.canVirtualize(environment,
|
||||
aspectNode));
|
||||
|
||||
addTypeTemplate(TEST_ASPECT,
|
||||
TEST_TEMPLATE_1_JS_CLASSPATH);
|
||||
|
||||
assertTrue(typeVirtualizationMethod.canVirtualize(environment,
|
||||
aspectNode));
|
||||
|
||||
}
|
||||
|
||||
public void testVirtualizeAspect() throws Exception
|
||||
{
|
||||
ChildAssociationRef templateContentChildRef = addTypeTemplate(TEST_ASPECT,
|
||||
TEST_TEMPLATE_1_JS_CLASSPATH);
|
||||
virtualize(templateContentChildRef.getChildRef(),
|
||||
ContentModel.TYPE_FOLDER,
|
||||
TEST_ASPECT);
|
||||
}
|
||||
|
||||
public void testVirtualizeType() throws Exception
|
||||
{
|
||||
ChildAssociationRef templateContentChildRef = addTypeTemplate(TEST_FOLDER_TYPE,
|
||||
TEST_TEMPLATE_1_JS_CLASSPATH);
|
||||
|
||||
virtualize(templateContentChildRef.getChildRef(),
|
||||
TEST_FOLDER_TYPE);
|
||||
}
|
||||
|
||||
private void virtualize(NodeRef expectedTemplateNodeRef, QName fodlerType, QName... aspects) throws Exception
|
||||
{
|
||||
|
||||
ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(),
|
||||
"TypeVirtualized",
|
||||
fodlerType);
|
||||
NodeRef typeNode = typedNodeAssocRef.getChildRef();
|
||||
|
||||
for (QName aspect : aspects)
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
nodeService.addAspect(typeNode,
|
||||
aspect,
|
||||
Collections.<QName, Serializable> emptyMap());
|
||||
super.setUp();
|
||||
typeVirtualizationMethod = ctx.getBean("typeVirtualizationMethod",
|
||||
TypeVirtualizationMethod.class);
|
||||
}
|
||||
|
||||
assertTrue(typeVirtualizationMethod.canVirtualize(environment,
|
||||
typeNode));
|
||||
@Override
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
typeVirtualizationMethod.setQnameFilters(virtualizationConfigTestBootstrap.getTypeTemplatesQNameFilter());
|
||||
}
|
||||
|
||||
Reference theVirtualizedNode = typeVirtualizationMethod.virtualize(environment,
|
||||
typeNode);
|
||||
assertEquals(Protocols.VANILLA.protocol,
|
||||
theVirtualizedNode.getProtocol());
|
||||
public void testFiltering() throws Exception
|
||||
{
|
||||
typeVirtualizationMethod.setQnameFilters("st:site");
|
||||
|
||||
List<Parameter> parameters = theVirtualizedNode.getParameters();
|
||||
ResourceParameter vanillaResourceParameter = (ResourceParameter) parameters
|
||||
.get(VanillaProtocol.VANILLA_TEMPLATE_PARAM_INDEX);
|
||||
Resource vanillaResource = vanillaResourceParameter.getValue();
|
||||
ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(),
|
||||
"TypeVirtualized",
|
||||
TEST_FOLDER_TYPE);
|
||||
NodeRef virtuaChildRef = typedNodeAssocRef.getChildRef();
|
||||
assertFalse(typeVirtualizationMethod.canVirtualize(environment,
|
||||
virtuaChildRef));
|
||||
|
||||
NodeRef resourceNodeRef = vanillaResource.processWith(new ResourceProcessor<NodeRef>()
|
||||
addTypeTemplate(TEST_FOLDER_TYPE,
|
||||
TEST_TEMPLATE_1_JS_CLASSPATH);
|
||||
|
||||
assertTrue(typeVirtualizationMethod.canVirtualize(environment,
|
||||
virtuaChildRef));
|
||||
|
||||
try
|
||||
{
|
||||
// invalid prefix
|
||||
typeVirtualizationMethod.setQnameFilters("invalid:site");
|
||||
fail("Should not be able to se invalib filters.");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
// as expected
|
||||
}
|
||||
|
||||
assertTrue(typeVirtualizationMethod.canVirtualize(environment,
|
||||
virtuaChildRef));
|
||||
|
||||
typeVirtualizationMethod.setQnameFilters("alf:site");
|
||||
|
||||
assertFalse(typeVirtualizationMethod.canVirtualize(environment,
|
||||
virtuaChildRef));
|
||||
|
||||
typeVirtualizationMethod.setQnameFilters("st:*");
|
||||
|
||||
assertTrue(typeVirtualizationMethod.canVirtualize(environment,
|
||||
virtuaChildRef));
|
||||
|
||||
typeVirtualizationMethod.setQnameFilters("alf:site");
|
||||
|
||||
assertFalse(typeVirtualizationMethod.canVirtualize(environment,
|
||||
virtuaChildRef));
|
||||
|
||||
typeVirtualizationMethod.setQnameFilters("*");
|
||||
|
||||
assertTrue(typeVirtualizationMethod.canVirtualize(environment,
|
||||
virtuaChildRef));
|
||||
|
||||
typeVirtualizationMethod.setQnameFilters("none");
|
||||
|
||||
assertFalse(typeVirtualizationMethod.canVirtualize(environment,
|
||||
virtuaChildRef));
|
||||
|
||||
}
|
||||
|
||||
public void testVirtualizeCmFolder_recusive() throws Exception
|
||||
{
|
||||
ChildAssociationRef templateContentChildRef = addTypeTemplate(ContentModel.TYPE_FOLDER,
|
||||
TEST_TEMPLATE_1_JS_CLASSPATH);
|
||||
virtualize(templateContentChildRef.getChildRef(),
|
||||
ContentModel.TYPE_FOLDER);
|
||||
}
|
||||
|
||||
public void testCanVirtualize() throws Exception
|
||||
{
|
||||
ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(),
|
||||
"TypeVirtualized",
|
||||
TEST_FOLDER_TYPE);
|
||||
NodeRef typeNode = typedNodeAssocRef.getChildRef();
|
||||
|
||||
assertFalse(typeVirtualizationMethod.canVirtualize(environment,
|
||||
typeNode));
|
||||
|
||||
addTypeTemplate(TEST_FOLDER_TYPE,
|
||||
TEST_TEMPLATE_1_JS_CLASSPATH);
|
||||
|
||||
assertTrue(typeVirtualizationMethod.canVirtualize(environment,
|
||||
typeNode));
|
||||
|
||||
}
|
||||
|
||||
public void testCanVirtualizeAspect() throws Exception
|
||||
{
|
||||
ChildAssociationRef aspectNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(),
|
||||
"TypeVirtualized",
|
||||
ContentModel.TYPE_FOLDER);
|
||||
NodeRef aspectNode = aspectNodeAssocRef.getChildRef();
|
||||
|
||||
nodeService.addAspect(aspectNode,
|
||||
TEST_ASPECT,
|
||||
Collections.<QName, Serializable> emptyMap());
|
||||
|
||||
assertFalse(typeVirtualizationMethod.canVirtualize(environment,
|
||||
aspectNode));
|
||||
|
||||
addTypeTemplate(TEST_ASPECT,
|
||||
TEST_TEMPLATE_1_JS_CLASSPATH);
|
||||
|
||||
assertTrue(typeVirtualizationMethod.canVirtualize(environment,
|
||||
aspectNode));
|
||||
|
||||
}
|
||||
|
||||
public void testVirtualizeAspect() throws Exception
|
||||
{
|
||||
ChildAssociationRef templateContentChildRef = addTypeTemplate(TEST_ASPECT,
|
||||
TEST_TEMPLATE_1_JS_CLASSPATH);
|
||||
virtualize(templateContentChildRef.getChildRef(),
|
||||
ContentModel.TYPE_FOLDER,
|
||||
TEST_ASPECT);
|
||||
}
|
||||
|
||||
public void testVirtualizeType() throws Exception
|
||||
{
|
||||
ChildAssociationRef templateContentChildRef = addTypeTemplate(TEST_FOLDER_TYPE,
|
||||
TEST_TEMPLATE_1_JS_CLASSPATH);
|
||||
|
||||
virtualize(templateContentChildRef.getChildRef(),
|
||||
TEST_FOLDER_TYPE);
|
||||
}
|
||||
|
||||
private void virtualize(NodeRef expectedTemplateNodeRef, QName fodlerType, QName... aspects) throws Exception
|
||||
{
|
||||
|
||||
@Override
|
||||
public NodeRef process(Resource resource) throws ResourceProcessingError
|
||||
ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(),
|
||||
"TypeVirtualized",
|
||||
fodlerType);
|
||||
NodeRef typeNode = typedNodeAssocRef.getChildRef();
|
||||
|
||||
for (QName aspect : aspects)
|
||||
{
|
||||
fail("Inavlid resource type");
|
||||
return null;
|
||||
nodeService.addAspect(typeNode,
|
||||
aspect,
|
||||
Collections.<QName, Serializable> emptyMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeRef process(ClasspathResource classpath) throws ResourceProcessingError
|
||||
{
|
||||
fail("Inavlid resource type");
|
||||
return null;
|
||||
}
|
||||
assertTrue(typeVirtualizationMethod.canVirtualize(environment,
|
||||
typeNode));
|
||||
|
||||
@Override
|
||||
public NodeRef process(RepositoryResource repository) throws ResourceProcessingError
|
||||
{
|
||||
RepositoryLocation location = repository.getLocation();
|
||||
return location.asNodeRef(environment);
|
||||
}
|
||||
});
|
||||
Reference theVirtualizedNode = typeVirtualizationMethod.virtualize(environment,
|
||||
typeNode);
|
||||
assertEquals(Protocols.VANILLA.protocol,
|
||||
theVirtualizedNode.getProtocol());
|
||||
|
||||
assertEquals(expectedTemplateNodeRef,
|
||||
resourceNodeRef);
|
||||
List<Parameter> parameters = theVirtualizedNode.getParameters();
|
||||
ResourceParameter vanillaResourceParameter = (ResourceParameter) parameters
|
||||
.get(VanillaProtocol.VANILLA_TEMPLATE_PARAM_INDEX);
|
||||
Resource vanillaResource = vanillaResourceParameter.getValue();
|
||||
|
||||
NodeRef resourceNodeRef = vanillaResource.processWith(new ResourceProcessor<NodeRef>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public NodeRef process(Resource resource) throws ResourceProcessingError
|
||||
{
|
||||
fail("Inavlid resource type");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeRef process(ClasspathResource classpath) throws ResourceProcessingError
|
||||
{
|
||||
fail("Inavlid resource type");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeRef process(RepositoryResource repository) throws ResourceProcessingError
|
||||
{
|
||||
RepositoryLocation location = repository.getLocation();
|
||||
return location.asNodeRef(environment);
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(expectedTemplateNodeRef,
|
||||
resourceNodeRef);
|
||||
}
|
||||
|
||||
private synchronized ChildAssociationRef addTypeTemplate(QName theType, String cp)
|
||||
{
|
||||
NodeRefExpression templatesLocationExpr = virtualizationConfigTestBootstrap.getTypeTemplatesPath();
|
||||
NodeRef templatesLocation = templatesLocationExpr.resolve();
|
||||
|
||||
assertNotNull(templatesLocation);
|
||||
|
||||
final String prefixedType = theType.toPrefixString(environment.getNamespacePrefixResolver());
|
||||
String contentName = prefixedType;
|
||||
contentName = contentName.replaceAll(":",
|
||||
"_")
|
||||
+ ".json";
|
||||
|
||||
InputStream testTemplsteJsonIS = getClass().getResourceAsStream(cp);
|
||||
ChildAssociationRef templateContentChildRef = createContent(templatesLocation,
|
||||
contentName,
|
||||
testTemplsteJsonIS,
|
||||
"application/json",
|
||||
"UTF-8",
|
||||
ContentModel.TYPE_CONTENT);
|
||||
|
||||
typeVirtualizationMethod.setQnameFilters(prefixedType);
|
||||
|
||||
return templateContentChildRef;
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized ChildAssociationRef addTypeTemplate(QName theType, String cp)
|
||||
public static class Unit extends TestCase
|
||||
{
|
||||
NodeRefExpression templatesLocationExpr = virtualizationConfigTestBootstrap.getTypeTemplatesPath();
|
||||
NodeRef templatesLocation = templatesLocationExpr.resolve();
|
||||
public void testQNameFiltersSetter_invalidFilters() throws Exception
|
||||
{
|
||||
assertIllegalQNameFilters(null,
|
||||
this);
|
||||
assertIllegalQNameFilters("",
|
||||
this);
|
||||
assertIllegalQNameFilters(":",
|
||||
this);
|
||||
assertIllegalQNameFilters("vm:",
|
||||
this);
|
||||
assertIllegalQNameFilters(":vm",
|
||||
this);
|
||||
assertIllegalQNameFilters("vm:fooBar,vm:",
|
||||
this);
|
||||
// undefined prefix
|
||||
assertIllegalQNameFilters("vm:anAspect",
|
||||
this);
|
||||
}
|
||||
|
||||
assertNotNull(templatesLocation);
|
||||
public void testQNameFiltersSetter_validFilters() throws Exception
|
||||
{
|
||||
assertQNameFilters("st:site",
|
||||
this);
|
||||
assertQNameFilters("st:site,cm:folder",
|
||||
this);
|
||||
assertQNameFilters("st:site,cm:test-folder",
|
||||
this);
|
||||
assertQNameFilters("st:*",
|
||||
this);
|
||||
assertQNameFilters("st:*,cm:*",
|
||||
this);
|
||||
|
||||
final String prefixedType = theType.toPrefixString(environment.getNamespacePrefixResolver());
|
||||
String contentName = prefixedType;
|
||||
contentName = contentName.replaceAll(":",
|
||||
"_") + ".json";
|
||||
assertQNameFilters("*",
|
||||
this);
|
||||
|
||||
InputStream testTemplsteJsonIS = getClass().getResourceAsStream(cp);
|
||||
ChildAssociationRef templateContentChildRef = createContent(templatesLocation,
|
||||
contentName,
|
||||
testTemplsteJsonIS,
|
||||
"application/json",
|
||||
"UTF-8",
|
||||
ContentModel.TYPE_CONTENT);
|
||||
assertQNameFilters("none",
|
||||
this);
|
||||
|
||||
String regexp = theType.toString();
|
||||
regexp = regexp.replaceAll("\\{",
|
||||
"\\\\{");
|
||||
regexp = regexp.replaceAll("\\}",
|
||||
"\\\\}");
|
||||
regexp = regexp.replaceAll("\\:",
|
||||
"\\\\:");
|
||||
regexp = regexp.replaceAll("\\.",
|
||||
"\\\\.");
|
||||
typeVirtualizationMethod.setQnameFilterRegexp(regexp);
|
||||
}
|
||||
}
|
||||
|
||||
return templateContentChildRef;
|
||||
private static NamespacePrefixResolver mockNamespacePrefixResolver()
|
||||
{
|
||||
NamespacePrefixResolver mockNamespacePrefixResolver = Mockito.mock(NamespacePrefixResolver.class,
|
||||
|
||||
new ThrowsException(new NamespaceException("Mock exception ")));
|
||||
|
||||
Mockito
|
||||
.doReturn(Arrays.<String> asList(SiteModel.SITE_MODEL_PREFIX))
|
||||
.when(mockNamespacePrefixResolver)
|
||||
.getPrefixes(SiteModel.SITE_MODEL_URL);
|
||||
Mockito.doReturn(SiteModel.SITE_MODEL_URL).when(mockNamespacePrefixResolver).getNamespaceURI(
|
||||
SiteModel.SITE_MODEL_PREFIX);
|
||||
|
||||
Mockito
|
||||
.doReturn(Arrays.<String> asList(NamespaceService.CONTENT_MODEL_PREFIX))
|
||||
.when(mockNamespacePrefixResolver)
|
||||
.getPrefixes(NamespaceService.CONTENT_MODEL_1_0_URI);
|
||||
Mockito.doReturn(NamespaceService.CONTENT_MODEL_1_0_URI).when(mockNamespacePrefixResolver).getNamespaceURI(
|
||||
NamespaceService.CONTENT_MODEL_PREFIX);
|
||||
|
||||
Mockito
|
||||
.doReturn("mock(NamespacePrefixResolver)@" + TypeVirtualizationMethod.class.toString())
|
||||
.when(mockNamespacePrefixResolver)
|
||||
.toString();
|
||||
return mockNamespacePrefixResolver;
|
||||
}
|
||||
|
||||
private static void assertIllegalQNameFilters(String filters, TestCase test)
|
||||
{
|
||||
TypeVirtualizationMethod tvm = new TypeVirtualizationMethod();
|
||||
try
|
||||
{
|
||||
tvm.setNamespacePrefixResolver(mockNamespacePrefixResolver());
|
||||
tvm.setQnameFilters(filters);
|
||||
TestCase.fail("Should not be able to set filters string " + filters);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
// void as expected
|
||||
logger.info(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertQNameFilters(String filters, TestCase test)
|
||||
{
|
||||
TypeVirtualizationMethod tvm = new TypeVirtualizationMethod();
|
||||
tvm.setNamespacePrefixResolver(mockNamespacePrefixResolver());
|
||||
tvm.setQnameFilters(filters);
|
||||
}
|
||||
|
||||
public static Test suite()
|
||||
{
|
||||
TestSuite suite = new TestSuite();
|
||||
suite.addTest(new JUnit4TestAdapter(Integration.class));
|
||||
suite.addTest(new JUnit4TestAdapter(Unit.class));
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
@@ -22,19 +22,69 @@ package org.alfresco.repo.virtual.template;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.virtual.VirtualizationIntegrationTest;
|
||||
import org.alfresco.repo.virtual.ref.NewVirtualReferenceMethod;
|
||||
import org.alfresco.repo.virtual.ref.Protocols;
|
||||
import org.alfresco.repo.virtual.ref.Reference;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchParameters;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ApplyTemplateMethodTest extends VirtualizationIntegrationTest
|
||||
{
|
||||
@Test
|
||||
public void testExecute_vanillaISO9075ActualPath() throws Exception
|
||||
{
|
||||
ChildAssociationRef iso9075FolderAssoc = createFolder(testRootFolder.getNodeRef(),
|
||||
"Acutal ISO9075 Node");
|
||||
NodeRef iso9075Folder = iso9075FolderAssoc.getChildRef();
|
||||
|
||||
NewVirtualReferenceMethod newVirtualReferenceMethod = new NewVirtualReferenceMethod(TEST_TEMPLATE_5_JSON_SYS_PATH,
|
||||
"/",
|
||||
iso9075Folder,
|
||||
VANILLA_PROCESSOR_JS_CLASSPATH);
|
||||
|
||||
ApplyTemplateMethod applyTemplateMethod = new ApplyTemplateMethod(environment);
|
||||
|
||||
Reference ref = Protocols.VANILLA.protocol.dispatch(newVirtualReferenceMethod,
|
||||
null);
|
||||
VirtualFolderDefinition structure = ref.execute(applyTemplateMethod);
|
||||
|
||||
VirtualFolderDefinition sfp5 = structure.findChildByName("SpecialFilingPath5");
|
||||
VirtualQuery query = sfp5.getQuery();
|
||||
|
||||
assertEquals("(PATH:'/app:company_home/cm:TestFolder/cm:Acutal_x0020_ISO9075_x0020_Node/cm:Space_x0020_Sub_x0020_Folder/*') and =cm:description:'SpecialFilingPath_5'",
|
||||
query.getQueryString());
|
||||
|
||||
ChildAssociationRef iso9075SubFolderAssoc = createFolder(iso9075Folder,
|
||||
"Space Sub Folder");
|
||||
|
||||
ChildAssociationRef someContentAssoc = createContent(iso9075SubFolderAssoc.getChildRef(),
|
||||
"someContent");
|
||||
|
||||
nodeService.setProperty(someContentAssoc.getChildRef(),
|
||||
ContentModel.PROP_DESCRIPTION,
|
||||
"SpecialFilingPath_5");
|
||||
|
||||
// check query for validity
|
||||
SearchParameters searchParameters = new SearchParameters();
|
||||
|
||||
searchParameters.setQuery(query.getQueryString());
|
||||
searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
|
||||
searchParameters.setLanguage(query.getLanguage());
|
||||
ResultSet qresult = searchService.query(searchParameters);
|
||||
assertEquals(1,
|
||||
qresult.getNumberFound());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteSysClasspath() throws Exception
|
||||
public void testExecute_virtualSysClasspath() throws Exception
|
||||
{
|
||||
ApplyTemplateMethod applyTemplateMethod = new ApplyTemplateMethod(environment);
|
||||
|
||||
@@ -66,7 +116,7 @@ public class ApplyTemplateMethodTest extends VirtualizationIntegrationTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteRepositoryJSON() throws Exception
|
||||
public void testExecute_vanillaRepositoryJSON() throws Exception
|
||||
{
|
||||
ChildAssociationRef templateAssoc = createContent(testRootFolder.getNodeRef(),
|
||||
"template1.json",
|
||||
|
@@ -28,7 +28,7 @@ import org.junit.Test;
|
||||
public class TemplateFilingRuleTest extends VirtualizationIntegrationTest
|
||||
{
|
||||
@Test
|
||||
public void testISO9075FilingSubPath() throws Exception
|
||||
public void testFilingSubPath_specialCharacters() throws Exception
|
||||
{
|
||||
NodeRef vfNodeRef = createVirtualizedFolder(testRootFolder.getNodeRef(),
|
||||
"Template 6 With Spaces",
|
||||
@@ -56,7 +56,7 @@ public class TemplateFilingRuleTest extends VirtualizationIntegrationTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testISO9075FilingPath() throws Exception
|
||||
public void testFilingPath_specialCharacters() throws Exception
|
||||
{
|
||||
NodeRef vfNodeRef = createVirtualizedFolder(testRootFolder.getNodeRef(),
|
||||
"Template 6 With Spaces",
|
||||
|
@@ -81,7 +81,7 @@
|
||||
"description":"SpecialFilingPath5",
|
||||
"search":{
|
||||
"language":"fts-alfresco",
|
||||
"query":"=cm:description:'SpecialFilingPath_5'"
|
||||
"query":"(PATH:'%ACTUAL_PATH%/cm:Space_x0020_Sub_x0020_Folder/*') and =cm:description:'SpecialFilingPath_5'"
|
||||
},
|
||||
"filing":{
|
||||
"path":"%ACTUAL_PATH%/cm:Space_x0020_Sub_x0020_Folder",
|
||||
|
@@ -32,7 +32,7 @@
|
||||
<property name="path" value="${virtual.download.associations.folder}" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="typeTemplatesQNameFilterRegexp" value="${virtual.folders.config.type.templates.qname.filter.regexp}" />
|
||||
<property name="typeTemplatesQNameFilter" value="${virtual.folders.config.type.templates.qname.filter}" />
|
||||
</bean>
|
||||
<bean id="test.config.hash.store" class="org.alfresco.repo.virtual.ref.HashStoreConfiguration.HashStoreConfigurationBean">
|
||||
<property name="classpathsHashes" value="/org/alfresco/repo/virtual/template->8,/org/alfresco/repo/virtual/template/testTemplate1.json->9"/>
|
||||
|
Reference in New Issue
Block a user